html node 增加需两步:
1 创建要增加的element, 给element 赋属性
2. 找到相应的节点,appendChild
下面是一段 mozilla scriptish 脚本的例子
有几个注意的地方
1. 包裹 function() 的括号,最初我没写外边这对(), 出错:Exception: function statement requires a name
也就是说不带(),只是个declare ,不是调用
2. createElement, 参考: http://www.cnblogs.com/penny/archive/2008/09/01/1281293.html
3. document.head 是 HTML5才支持的写法,不支持就要写成 document.getElementsByTagName("head")[0]
//------------例子-------------------
(function(){
if(typeof jQuery=='undefined'){
var jquerynode1=document.createElement("link");
jquerynode1.setAttribute("rel","stylesheet");
jquerynode1.setAttribute("href","http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css");
var jquerynode2=document.createElement("script");
jquerynode2.setAttribute("src","http://code.jquery.com/jquery-1.8.3.min.js");
var jquerynode3=document.createElement("script");
jquerynode3.setAttribute("src","http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js");
document.head.appendChild(jquerynode1);
document.head.appendChild(jquerynode2);
document.head.appendChild(jquerynode3);
}
})();
//--------------------end ----------------
1 创建要增加的element, 给element 赋属性
2. 找到相应的节点,appendChild
下面是一段 mozilla scriptish 脚本的例子
有几个注意的地方
1. 包裹 function() 的括号,最初我没写外边这对(), 出错:Exception: function statement requires a name
也就是说不带(),只是个declare ,不是调用
2. createElement, 参考: http://www.cnblogs.com/penny/archive/2008/09/01/1281293.html
3. document.head 是 HTML5才支持的写法,不支持就要写成 document.getElementsByTagName("head")[0]
//------------例子-------------------
(function(){
if(typeof jQuery=='undefined'){
var jquerynode1=document.createElement("link");
jquerynode1.setAttribute("rel","stylesheet");
jquerynode1.setAttribute("href","http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css");
var jquerynode2=document.createElement("script");
jquerynode2.setAttribute("src","http://code.jquery.com/jquery-1.8.3.min.js");
var jquerynode3=document.createElement("script");
jquerynode3.setAttribute("src","http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js");
document.head.appendChild(jquerynode1);
document.head.appendChild(jquerynode2);
document.head.appendChild(jquerynode3);
}
})();
//--------------------end ----------------