jQuery html()和innerHTML [英] JQuery html() vs. innerHTML

查看:102
本文介绍了jQuery html()和innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我,我可以完全依赖jQuery html()方法,它将像 innerHTML ?在 innerHTML 和jquery html()方法之间有什么区别吗?如果这两个都做同样的工作,我可以使用jquery html()方法代替 innerHTML



我的问题是:我正在处理已设计的页面,页面包含表格,在javascript中正在使用 innerHTML 属性要动态填充它们,应用程序在Firefox 上正常工作,但是Internet Explorer 触发错误未知的运行时异常。我使用jquery html()方法和 IE 错误已经停止。但我不确定它会适用于所有浏览器,我不确定将所有 innerHTML 属性替换为jquery html()方法。请仔细阅读



非常感谢

解决方案



.html()只会调用 .innerHTML 在对nodeType&东东。它还使用一个 try / catch 块,其中它首先使用 innerHTML ,如果失败,它将会回退优雅的jQuerys .empty() + append()


Please tell me, Can I rely completely upon jQuery html() method that it'll perform like innerHTML? is there any difference between innerHTML and jquery html() method? and if these both do the same work can I used jquery html() method in place of 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, application is working fine on Firefox but Internet Explorer fires error "unknown runtime exception". I used jquery html() method and IE error has stopped. but I'm not sure it will work for all browsers and I'm not sure to replace all innerHTML properties to jquery html() method. pls suggest

Thanks a lot

解决方案

To answer your question:

.html() will just call .innerHTML after doing some checks for nodeType's & stuff. It also uses a try/catch block where it trys to use innerHTML first and if that fails, it'll fallback gracefully to jQuerys .empty() + append()

这篇关于jQuery html()和innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆