首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jquery 创建dom 用的是createElement还是innerHTML?该怎么解决

2012-05-27 
jquery 创建dom 用的是createElement还是innerHTML?最近分析了一下js里面innerHTML 和 createElement方式

jquery 创建dom 用的是createElement还是innerHTML?
最近分析了一下js里面innerHTML 和 createElement方式创建dom的效率,与浏览器有关,但总的来说innerHTML更优越一些。
不过我始终没搞清楚jquery到底是用哪种方式把html构造成dom的
eg:$("<div><table></tr..........</div>")

jquery的源码不太好分析,哪位高人能指点一下?

[解决办法]

引用If the HTML is more complex than a single tag without attributes, as it is in the above example, the actual creation of the elements is handled by the browser's innerHTML mechanism. In most cases, jQuery creates a new <div> element and sets the innerHTML property of the element to the HTML snippet that was passed in. When the parameter has a single tag, such as $('<img />') or $('<a></a>'), jQuery creates the element using the native JavaScript createElement() function.

热点排行