免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2014 | 回复: 1
打印 上一主题 下一主题

jquery 选中checkbox兼容问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-06 10:29 |只看该作者 |倒序浏览
jquery 选中checkbox兼容问题






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




Html代码
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <script src="lib/jquery-1.6.4.min.js" type="text/javascript"></script>  
  6. <!--script src="lib/jquery-1.4.4.js" type="text/javascript"></script-->  
  7. <script type="text/javascript">  
  8. $(document).ready(   
  9.     function(){   
  10.         $("#jianrong").click(sovle_jquery_virsion);   
  11.         $("#test").click(function(){   
  12.             //如果是1.4版本得到的数据时boolean类型的   
  13.             //如果是1.6版本得到的结果是字符串   
  14.             if(true == $("#show_img_title").attr("checked")){   
  15.                 alert("是字符串true");   
  16.             }   
  17.             if("checked" == $("#show_img_title").attr("checked")){   
  18.                 alert("是字符串checked!");   
  19.             }   
  20.         });   
  21.     }   
复制代码
);   
  
//解决不同版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>无标
  1. 题文档</title>  
  2. </head>  
  3. <input type="checkbox" id="show_img_title" style="vertical-align:-3px;"><label style="margin: 0 0 0 4px;" for="show_img_title">照片标题描述带入日记</label><br>  
  4. <button id="test">test</button><br>  
  5. <button id="jianrong">兼容性问题测试</button>  
  6. <body>  
  7. </body>  
  8. </html>  

  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  10. <html xmlns="http://www.w3.org/1999/xhtml">
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  13. <script src="lib/jquery-1.6.4.min.js" type="text/javascript"></script>
  14. <!--script src="lib/jquery-1.4.4.js" type="text/javascript"></script-->
  15. <script type="text/javascript">
  16. $(document).ready(
  17.         function(){
  18.                 $("#jianrong").click(sovle_jquery_virsion);
  19.                 $("#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>
  

论坛徽章:
0
2 [报告]
发表于 2012-03-12 19:59 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP