<html>
<head>
<script src="../js/jquery-1.4.2.min.js" type="text/javascript"></script><script>
//function loadJs(){
var script = document.createElement('script');
script.type = 'type/javascript';
script.src = 'test.js';
script.id = 'loadJsID';
document.getElementsByTagName('head')[0].appendChild(script);// jQuery.getScript("test.js",function(){});
//}function clickMe(){
// alert(document.getElementById("loadJsID").textContent);
// alert(document.getElementById("loadJsID").src);
test();
}//window.onload = loadJs;</script></head>
<body>
<h1>javascript and css load test.</h1>
<input type="button" value="Click Me" onclick="clickMe();">
</body></html>test.js:
function test(){
alert(9999999);
}test();我在网上看了一下,多数也是说是这么加载的,但我在IE8,FF3.6下均没有加载成功。而用
jQuery.getScript("test.js",function(){});则可以加载。
请教失败原因,还有就是jquery加载的原理。还有就是动态加载CSS要怎么办。谢谢。
<head>
<script src="../js/jquery-1.4.2.min.js" type="text/javascript"></script><script>
//function loadJs(){
var script = document.createElement('script');
script.type = 'type/javascript';
script.src = 'test.js';
script.id = 'loadJsID';
document.getElementsByTagName('head')[0].appendChild(script);// jQuery.getScript("test.js",function(){});
//}function clickMe(){
// alert(document.getElementById("loadJsID").textContent);
// alert(document.getElementById("loadJsID").src);
test();
}//window.onload = loadJs;</script></head>
<body>
<h1>javascript and css load test.</h1>
<input type="button" value="Click Me" onclick="clickMe();">
</body></html>test.js:
function test(){
alert(9999999);
}test();我在网上看了一下,多数也是说是这么加载的,但我在IE8,FF3.6下均没有加载成功。而用
jQuery.getScript("test.js",function(){});则可以加载。
请教失败原因,还有就是jquery加载的原理。还有就是动态加载CSS要怎么办。谢谢。
var script = document.createElement('script');
script.type = 'type/javascript';
script.src = 'test.js';
script.id = 'loadJsID';
ddocument.body.appendChild(script);}
<script>
//function loadJs(){
var script = document.createElement('script');
//script.type = 'type/javascript';
script.src = 'test.js';
script.id = 'loadJsID';
document.getElementsByTagName('head')[0].appendChild(script);// jQuery.getScript("test.js",function(){});
//}function clickMe(){
// alert(document.getElementById("loadJsID").textContent);
// alert(document.getElementById("loadJsID").src);
test();
}//window.onload = loadJs;</script>//script.type = 'type/javascript';
去掉这句。
//script.type = 'type/javascript';
去掉这句。
确实是可以了。但为什么要除掉这个呢?
谢谢各位了。
发现一处明显的错误
是text/javascript不是type/javascript