如何在附加脚本后触发加载

时间:2014-09-28 18:21:50

标签: jquery ckeditor

我正在使用CKEditor,这个编辑器在变量 - editor.document。$创建一个新的DOM树。我已将JS脚本附加到editor.document。$。head,但我不明白如何触发它们实际加载:

CKEDITOR.on( 'instanceReady', function( ev ) {
    editor = ev.editor;
    if(editor.name == 'edit-body-und-0-value'){
     var head = editor.document.getHead();
     var body = editor.document.getBody();

     var s0 = editor.document.$.createElement( 'script' );
     s0.type = 'text/javascript';
     s0.onload = function() {
         console.log( 'script path/jquery-1.11.0.min.js loaded' );
     };
     s0.src = '/path/jquery-1.11.0.min.js';
     s0.$ = s0;
     head.append(s0);

     var s2 = editor.document.$.createElement( 'script' );
     s2.type = 'text/javascript';
     s2.onload = function() {
         console.log( 'script path/jquery-ui/jquery-ui-1.10.3.custom.min.js loaded' );
     };
     s2.src = '/path/jquery-ui/jquery-ui-1.10.3.custom.min.js';
     s2.$ = s2;
     head.append(s2);

     jQuery(editor.document.$).ready(function($) {
         $ = jQuery(editor.document.$);
         $.trigger("load");
         Some.init();
         Layout.init();
         ...
      });
    }
});

我可以看到附加到头部的脚本,但是没有加载它们。他们后来得到了装载,但为时已晚。我想让它们在" init"之前加载。叫做。怎么做?谢谢

0 个答案:

没有答案