本文介绍了如何有条件地包括外部javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此代码:
<script src="http://external/js/file/url.js">
</script>
我想做这样的事情-
<script>
if(2>1){
//include http://external/js/file/url.js
}
</script>
有什么主意吗?
推荐答案
在.这样的代码可能符合您一直在寻找的东西
This question has been asked before in Include a Javascript File in another Javascript File.This peice of code may fit what you have been looking for
function include(filename)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
head.appendChild(script)
}
如果该脚本不起作用,我建议您仔细阅读并阅读上面的文章:.
if that script does not work, i suggest you to look over and read the post above: Include a Javascript File in another Javascript File.
我希望这会有所帮助,可能不是您一直在寻找的答案,但可能会有所帮助.
I hope this helps, it may not be the answer you had been looking for, but it may just help.
这篇关于如何有条件地包括外部javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!