我能否完全依赖jQuery的html()方法,其行为与innerHTML相同?innerHTML和jQuery的html()方法有什么区别吗?如果这两种方法都是一样的,我可以用jQuery的html()方法代替innerHTML吗?

My problem is: I am working on already designed pages, the pages contains tables and in JavaScript the innerHTML property is being used to populate them dynamically.

The application is working fine on Firefox but Internet Explorer fires an error: unknown runtime exception. I used jQuery's html() method and IE's error has disappeared. But I'm not sure it will work for all browsers and I'm not sure whether to replace all innerHTML properties with jQuery's html() method.

谢谢.

推荐答案

To answer your question:

.html()在判断 node 类型和其他内容后,只需拨打.innerHTML.它还使用try/catch块,try 先使用innerHTML,如果失败,它将优雅地回退到jQuery的.empty()+append()

Jquery相关问答推荐

无法通过单击从元素获取数据

通过 jQuery 提取 application/json 数据

jQuery:使用变量作为 Select 器

jQuery获取DOM node ?

标识符 (id) 是否有通配符 Select 器?

使用 jQuery 和 HTML 导出为 CSV

如何使用 jQuery 重置 jquery Select 的 Select 选项?

Chart.js 中饼图的点击事件

使用跨域帖子发送凭据?

使用 JQuery / JavaScript 调用/单击 mailto 链接

jQuery 插件:添加回调功能

JQuery:如果 div 可见

如何使用 jQuery 隐藏 div?

jQuery、复选框和 .is(":checked")

用作 Google Chrome 书签

在ajax请求中检测重定向?

jQuery确定匹配的类是否具有给定的ID

更改 div 的内容 - jQuery

如何删除集中的 contenteditable pre 周围的边框?

在 Firefox 上开发的 Javascript 在 IE 上失败的典型原因是什么?