当前位置: 代码迷 >> JavaScript >> 两个javascript其间函数的调用
  详细解决方案

两个javascript其间函数的调用

热度:149   发布时间:2012-09-12 09:21:30.0
两个javascript之间函数的调用
a.htm的内容
---------------------------------------------------
<html>
<head>
<script src=a.js type=text/javascript></script>
</head>
<body>
</body>
</html>

a.js 的内容
-------------------------------------------------
function load_b()
{
         // 先把b.js调入
var head = document.getElementsByTagName('head');
var testScript = document.createElement('script');
testScript.src = 'b.js';
testScript.type = 'text/javascript';
head[0].appendChild(testScript);
         // 现在就可以调用b.js中的test()函数了
test();
}
window.onload = load_b;
 
b.js 的内容
------------------------------------------------
function test()
{
   alert(bad);
}

  相关解决方案