我正在尝试将 yepnope.js 注入页面,然后使用 yepnope 加载其他 JS 文件。
Chrome 开发工具的网络选项卡显示 yepnope 已获取,元素选项卡显示元素已注入。但控制台选项卡显示:
Uncaught ReferenceError: yepnope is not defined
这是我的代码:
var betaApp = {
injectYepnope: function(url) {
var gp = document.createElement( 'script' );
gp.type = 'text/javascript';
gp.async = true;
gp.src = url;
gp.onload = betaApp.yepnopeLoaded;
// Only for IE 6 and 7
gp.onreadystatechange = function()
{
if( this.readyState == 'complete' )
{
betaApp.yepnopeLoaded();
}
}
document.body.appendChild(gp);
},
yepnopeLoaded: function() {
yepnope([
{
load: ['//cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js', 'http://raw.github.com/andris9/jStorage/master/jstorage.js'],
complete: function() {
betaApp.firstPartLoaded();
}
},
{
load: [
'http://code.jquery.com/jquery-1.8.2.min.js',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js',
'https://raw.github.com/Automattic/Iris/master/dist/iris.js',
'https://raw.github.com/cnkt/eksi-beta/master/ui/js/twitter-bootstrap/js/bootstrap-modal.js',
'https://raw.github.com/Automattic/Iris/master/src/iris.min.css'
],
complete: function() {
betaApp.allJsLoaded();
}
}
]);
}
};
betaApp.injectYepnope('https://raw.github.com/cnkt/eksi-beta/master/ui/js/yepnope.js');
提前致谢。