加载样式
添加js
function addCssByLink(url){
var doc=document;
var link=doc.createElement("link");
link.setAttribute("rel", "stylesheet");
link.setAttribute("type", "text/css");
link.setAttribute("href", url);
var heads = doc.getElementsByTagName("head");
if(heads.length)
heads[0].appendChild(link);
else
doc.documentElement.appendChild(link);
}
function addCssByStyle(cssString){
var doc=document;
var style=doc.createElement("style");
style.setAttribute("type", "text/css");
if(style.styleSheet){// IE
style.styleSheet.cssText = cssString;
} else {// w3c
var cssText = doc.createTextNode(cssString);
style.appendChild(cssText);
}
var heads = doc.getElementsByTagName("head");
if(heads.length)
heads[0].appendChild(style);
else
doc.documentElement.appendChild(style);
}
添加js
//动态添加js
var mapJs = doc.createElement("script");
mapJs.setAttribute("type","text/javascript");
mapJs.setAttribute("src","http://maps.google.com/maps/api/js?sensor=false");
//var heads = doc.getElementsByTagName("head");
doc.documentElement.appendChild(mapJs);