var $C = function(el){ return document.createElement(el); }; var $N = function(el){ return (typeof el == 'string')?document.getElementsByTagName(el):null; }; var Include = function(path){ var S = $C("SCRIPT"); S.type = "text/javascript"; S.src = path; $N("HEAD")[0].appendChild(S); };Include("http://www.***.com/test.js");
var $C = function(el){
return document.createElement(el);
};
var $N = function(el){
return (typeof el == 'string')?document.getElementsByTagName(el):null;
};
var Include = function(path){
var S = $C("SCRIPT");
S.type = "text/javascript";
S.src = path;
$N("HEAD")[0].appendChild(S);
};Include("http://www.***.com/test.js");
直接 inner 是不行的 ,请参照 2 楼 ,很好的方法 ,重用性也好
<body>
<script>
document.body.insertAdjacentHTML("afterbegin","<iframe><iframe>")
</script>
</body>
</html>
为什么插入iframe就可以,插入js就不行呢?
还有2楼的代码我用了,没有成功调用到js。
请各位高手指教
<body>
<script>
var s = document.createElement("script");
s.src="http://www.***.com/test.js";
s.type="text/javascript";
document.body.appendChild(s);
</script>
</body>
</html>
这样用的