问题介绍:

  1、由于我们的项目里面用了很多Iframe,在初始话加载的时候页面就会报错。一开始调试很久没找到什么原因,看打印结果页面会被两次load,只能一步步找,

  最后发现在document ready 的地方会被执行两次。

  2、之所以checkbox会勾选不上是因为自己的写法不规范,还有就是jQuery版本问题。

以下是详细介绍和解决办法:

  Iframe

    Error:Cannot read property '2' of null

a.html

 $(document).ready(function(){
2   console.log(1);
  createIframe('1');
});
$(document).ready(function(){
console.log(2);
createIframe('2');
});
function createIframe(id){
  $("body").append($("<iframe id='"+id+"' src='b.html'></iframe>"));
}

b.html

$(function(){
console.log('test-111');
createIframe();
});
$(function(){
console.log('test-222');
}); function createIframe(){
$("body").append($("<iframe></iframe>"));
}
</script>

    

    官方参考地址:http://bugs.jquery.com/ticket/7352

checkbox

我的写法如下:

    jquery-1.4.3

     $('.items').attr('checked','checked'); //勾选 OK

     $('.items').attr('checked',''); //不勾选 OK

    jquery-1.6+

     $('.items').attr('checked','checked'); //勾选 OK

     $('.items').attr('checked',''); // 不勾选 NO 修改为 $('.items').prop('checked','');

通用版本支持的(最新的jquery没有进行测试):

  $('.items').attr('checked',true);

  $('.items').attr('checked',false);

jQuery 1.6之前 ,.attr()方法在取某些 attribute 的值时,会返回 property 的值,这就导致了结果的不一致。

从 jQuery 1.6 开始, .prop()方法 方法返回 property 的值,而 .attr() 方法返回 attributes 的值。

如果自己想深入了解的可以去官网上找写资料。

最新文章

  1. 【原】iphone6来了,我该做点什么(兼容iphone6的方法)
  2. Freemarker与Servlet
  3. Spring中加载xml配置文件的六种方式
  4. spirng线程池的配置与使用
  5. php升级5.3到5.4,5.5,5.6
  6. 八、java集合类
  7. js调用高德API获取所在当前城市
  8. 《MFC游戏开发》笔记十 游戏中的碰撞检测进阶:地图类型&amp;障碍物判定
  9. Linux用户与用户组的详解
  10. [C入门 - 游戏编程系列] 贪吃蛇篇(六) - 蛇实现
  11. [Android]ADT Run时候报错:The connection to adb is down, and a severe error has occured
  12. bayboy下载安装
  13. unity插件开发——Selection
  14. JavaScript基礎知識
  15. BZOJ 4765: 普通计算姬 [分块 树状数组 DFS序]
  16. 如何正确使用const、static、extern
  17. android studio中使用lambda
  18. minimun depth of binary tree
  19. 关于RecyclerView嵌套导致item复用异常,界面异常的问题
  20. Laravel开发采坑系列问题

热门文章

  1. BeanUtils API中使用ConvertUtils向BeanUtils注册一个日期转换器
  2. windows环境下VS2013编译openSSL
  3. Silverlight分享一套企业开发主题
  4. 一个简单的JUnit项目
  5. 状压dp-poj-1170-Shopping Offers
  6. js创建及操作数组
  7. Mac 下tomcat的安装配置
  8. 组合数学第一发 hdu 2451 Simple Addition Expression
  9. JAVA-1-学习历程1:基础知识1
  10. 使用Httpwatch分析响应时间--转