您的位置:首页 > Web前端 > JQuery

jquery 选中checkbox兼容问题

2013-12-04 09:54 417 查看
今天在做一个checkbox选中功能的时候,在本地测试已经通过,但是把代码上传到服务器上测试却是功能不能正常工作!最后老大告诉我本地和线上的jquery插件不一致,虽然我知道jquery插件有浏览器兼容的问题,但是这个还是自己第一次遇到或者说是留意到这个问题,下面将我做的写下来,提供给大家学习

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="lib/jquery-1.6.4.min.js" type="text/javascript"></script>
<!--script src="lib/jquery-1.4.4.js" type="text/javascript"></script-->
<script type="text/javascript">
$(document).ready(
function(){
$("#jianrong").click(sovle_jquery_virsion);
$("#test").click(function(){
//如果是1.4版本得到的数据时boolean类型的
//如果是1.6版本得到的结果是字符串
if(true == $("#show_img_title").attr("checked")){
alert("是字符串true");
}
if("checked" == $("#show_img_title").attr("checked")){
alert("是字符串checked!");
}
});
}
);

//解决不同版jquery的问题,可以用下面的方式判断
function sovle_jquery_virsion(){
if("checked" == $('#show_img_title', parent.document.body).attr("checked") || true == $('#show_img_title', parent.document.body).attr("checked")){
alert("多选框被选中!");
}else{
alert("多选框没有被选中!");
}
}

</script>
<title>无标题文档</title>
</head>
<input type="checkbox" id="show_img_title" style="vertical-align:-3px;"><label style="margin: 0 0 0 4px;" for="show_img_title">照片标题描述带入日记</label><br>
<button id="test">test</button><br>
<button id="jianrong">兼容性问题测试</button>
<body>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: