中国开发网: 论坛: 程序员情感CBD: 贴子 473936
有狐: 给你个例子,从我以前一个js文件复制来的,详细内容你自己看MSDN
//to Insert Script :MSDN insertAdjacentHTML
//When using the insertAdjacentHTML method to insert script,
//you must include the DEFER attribute in the script element.
//body onload=insertScript()
/************
function insertScript(){
var sHTML="<input type=button onclick=" + "go2()" + " value='Click Me'><BR>"
var sScript='<SCRIPT DEFER>'
sScript = sScript + 'function go2(){ alert("Hello from inserted script.") }'
sScript = sScript + '</script' + '>';
ScriptDiv.insertAdjacentHTML("afterBegin",sHTML + sScript);
}

function insertScript(){
var div=document.createElement("DIV")
div.style.display="none"
document.body.appendChild(div)
var sScript='<'+'script DEFER>'
sScript += 'var deferValue=1000;'
sScript += '</script' + '>'
div.insertAdjacentHTML("AfterBegin", "<BR>"+sScript) // <BR>is important
}

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录