我尝试使用jquery,一些脚本加载,下载完成后我想执行一些代码。
我希望得到alert(1)
,但没有任何反应。正确下载脚本(在console
中查看)。
$.when(
$.getScript ("/framework/static/libs/ckeditor/ckeditor/ckeditor.js"),
$.getScript ("/framework/static/libs/ckeditor/ckeditor/config.js"),
$.getScript ("/framework/static/libs/ckeditor/ckeditor/skins/bootstrapck/editor_gecko.css"),
$.getScript ("/framework/static/libs/ckeditor/ckeditor/lang/de.js"),
$.getScript ("/framework/static/libs/ckeditor/ckeditor/adapters/jquery.js"),
$.Deferred(function( deferred ){$( deferred.resolve );})
).done(function() {
alert (1);
});
感谢您的帮助。
答案 0 :(得分:0)
我希望问题出在下面。
$.getScript ("/framework/static/libs/ckeditor/ckeditor/skins/bootstrapck/editor_gecko.css")
您可以在documentation中找到它使用GET HTTP请求从服务器加载 JavaScript文件,然后执行它。
对于css文件,您必须使用以下代码。
window.getStyle = function(file) {
var top = $('head > link[rel=stylesheet]').length ? $('head > link[rel=stylesheet]:last') : $('head > *:last');
top.after('<link rel="stylesheet" type="text/css" href="' + file + '">');
};
$.when(
$.getScript("/framework/static/libs/ckeditor/ckeditor/ckeditor.js"),
$.getScript("/framework/static/libs/ckeditor/ckeditor/config.js"), window.getStyle("/framework/static/libs/ckeditor/ckeditor/skins/bootstrapck/editor_gecko.css"),
$.getScript("/framework/static/libs/ckeditor/ckeditor/lang/de.js"),
$.getScript("/framework/static/libs/ckeditor/ckeditor/adapters/jquery.js"),
$.Deferred(function(deferred) {
$(deferred.resolve);
})
).done(function() {
alert(1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>