我有这样的代码:如何动态加载JavaScript文件?
<script type="text/javascript">
function js() {
var getJs = document.getElementById("jogo");
if (JS == true) { //if button JS is pressed - it is correct?
< script type = "text/javascript"
src = "file1.js" >
} else < script type = "text/javascript"
src = "file2.js" >
</script>
}
</script>
这是行不通的。我给了两个按钮,如果第一个按下,应该加载file1.js
。如果第二个按下,则应装入file2.js
。
我该怎么做?
你必须做一个eval – kjy112 2011-03-08 16:33:45
什么你的意思是与eval?谢谢 – user455318 2011-03-08 16:35:43
'if(JS == true)'dosent表示它被按下,它只是表示元素存在于DOM中,为什么不包含所有脚本,然后根据JS的存在调用适当的函数 – slier 2011-03-08 16:36:32