使用document.body.appendChild附加整个代码块
Using document.body.appendChild to append a whole code block?
是否可以使用appendChild附加整个代码块?这就是我想附加的内容:
<script type="text/javascript" src="some.js"></script>
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="styles-ie.css" media="all" />
<![endif]-->
<!--[if lt IE 7]>
<script type="text/javascript" src="85d6d1c5f8f9c87ae016eae0ee6994c7.js"></script>
<![endif]-->
我想我不能用appendChild附加它?
如果你使用纯JavaScript,你可以使用这个:
var body = document.body;
body.innerHTML += 'Whatever you want to append.';
function addLABjs(callback) {
var script = document.createElement("script");
script.setAttribute("src", "YourOtherScript.js");
script.addEventListener('load', function () {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
$LAB.script("YourOtherScript.js").wait()
.script("YourOtherScript.js")
.script("YourOtherScript.js").wait();
$(document).ready(function () {
});
}
addLABjs(main);
相关文章:
- jQuery document.ready停止代码
- Javascript的“document.write()”中的PHP代码
- document.getElementById为空..什么'I’我的代码错了.
- 如果事件发生后插入了检查代码,那么$(document).ready()会被激发吗
- JavaScript's替换与document.create()结合的函数-这个代码是做什么的
- document.location 在后续代码之后颁布
- $(document).ready() 在 IE 中使用 require.js 优化代码
- DOM 树操作 (document.createElement) 代码重用
- 如果代码在底部,那么将 $(document).ready 函数放在底部有什么意义
- 如何从代码隐藏中分配 $(document).ready 中的值
- 在 requirejs 中的 document.ready 之前执行代码
- Document.getElementById('Button').click();不触发代码隐藏
- 有人可以一点一点地向我解释这行代码:forprice.innerHTML=document.forms[0].eleme
- 为什么这个setInterval/document.write代码在Chrome上有效,但在Firefox上不起作用
- 将所有代码放在“$(document).ready”中是否安全
- 在 document.ready 中获取隐藏字段的值,asp.net 代码隐藏
- 使用document.body.appendChild附加整个代码块
- 使用不同的变量值多次执行外部javascript文件中的$(document).ready()中的代码
- .js代码中给出的document.location()函数在Internet Explorer中工作正常,但在Fire
- 等待第一个事件完成,然后继续使用document.ready代码