var bottomscript=document.createElement("<script>");
bottomscript.type="text/javascript";
bottomscript.src="inc/bottom.js";
document.body.appendChild(bottomscript);
$("mybottom").appendChild(bottomscript);
我用上面的代码就要实现等同于在页面中加入这段代码<script type="text/javascript" src="inc/bottom.js"></script>为什么不行呢 ?
bottomscript.type="text/javascript";
bottomscript.src="inc/bottom.js";
document.body.appendChild(bottomscript);
$("mybottom").appendChild(bottomscript);
我用上面的代码就要实现等同于在页面中加入这段代码<script type="text/javascript" src="inc/bottom.js"></script>为什么不行呢 ?
====》
var bottomscript=document.createElement("script");
用js动态引入js?你的js很大吗?还不如直接在页面写死呢
bottomscript.setAttribute("src", "inc/bottom.js");
bottomscript.setAttribute("type","text/javascript");
bottomscript.setAttribute("language","javascript"); //document.body.appendChild(bottomscript);
$("mybottom").appendChild(bottomscript);
我想插到某个div里,没用啊
document.getElementById("mybottom").appendChild(bottomscript);PS:执行上面语句时,要求mybottom已加载
<div id="mybottom"></div>
<script>
var bottomscript=document.createElement("script");
bottomscript.type="text/javascript";
bottomscript.src="inc/bottom.js";
document.getElementById("mybottom").appendChild(bottomscript);</script>我测试过好用的呀
你的方法不完全正确。
如果我的bottom.js里是alert()就可以。
如果是document.write("ssssssss")就不可以。
document.getElementById("mybottom").innerHTML = '<script type="text/javascript" '
+ 'src="inc/bottom.js"> </script> ';感觉楼主另有目的。但是什么呢?