日期:2014-05-17  浏览次数:20561 次

jquery的html方法处理style标签和script标签

jquery处理了html方法的各种情况

?

对应script为创建script对象,设置type属性,如果是远程的数据,设置src

如果是内联脚本,ie上为设置text属性为执行的脚本

firefox上位appendChild的方法添加document.createTextNode(text);

然后再head的位置,insertBefore(script , head.firstChild);

然后再移除掉

head.removeChild(script);

?

对应link标签

如果是firefox直接更新html

如果是ie,则需要将所有节点用div包起来,在前部添加一个文本节点例如div三个字,然后返回用div包起来的

div.childNodes,全部添加到一个documentFragment中去,然后再更新html.

?

可参考3989行

// IE can't serialize <link> and <script> tags normally
if ( !jQuery.support.htmlSerialize ) {
??? wrapMap._default = [ 1, "div<div>", "</div>" ];
}