我试图在js中加载QUnit,但QUnit.js中的addevent函数从未触发过,而且它就是不起作用:
var appendQUnit = document.createElement('script');
appendQUnit.src = 'js/utility/qunit/qunit.js';
appendQUnit.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(appendQUnit); 发布于 2010-05-20 18:53:55
您可以使用jquery的getScript,例如:
$.getScript('js/utility/qunit/qunit.js', function() {
// here you can handle the qunit code
});因为浏览器总是以异步模式加载javascript文件,所以您需要一些回调来放置处理新加载的js代码的代码。
发布于 2011-10-20 14:46:03
您可能还需要调用QUnit.load()来初始化QUnit:
$.getScript('js/utility/qunit/qunit.js', function(){
QUnit.load();
// here you can handle the qunit code
});https://stackoverflow.com/questions/2870750
复制相似问题