Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Js/jQuery include函数在IE中不起作用_Javascript_Jquery_Internet Explorer - Fatal编程技术网

Javascript Js/jQuery include函数在IE中不起作用

Javascript Js/jQuery include函数在IE中不起作用,javascript,jquery,internet-explorer,Javascript,Jquery,Internet Explorer,我有以下代码 function includeJSLib(lib, id, callback) { if (!document.getElementById(id)) { var s = document.createElement('script'); s.setAttribute('id', id); s.setAttribute('async', 'false'); s.setAttribute('type', 'text/javascript');

我有以下代码

function includeJSLib(lib, id, callback) {
if (!document.getElementById(id)) {
    var s = document.createElement('script');
    s.setAttribute('id', id);
    s.setAttribute('async', 'false');
    s.setAttribute('type', 'text/javascript');
    s.src = lib;
    document.getElementsByTagName('head')[0].appendChild(s);
    s.onload = callback;
} else {
    callback();
}
}
includeJSLib('https://code.jquery.com/jquery-1.11.3.min.js', 'jqueryInclude', function(){
jQuery(document).ready( function($) {
    if ($('body').hasClass('class')) { do something }
});
});
它将加载jQuery。在回调函数中有一些自定义代码。自定义代码在Firefox和Chrome中运行良好,但在IE中不起作用

internet Explorer完全忽略代码片段。在IE 10/11中测试

有人知道问题出在哪里吗

谢谢和问候, 氮氧化物

p、 IE调试器什么也没说,只是跳过了代码片段。对于IE,我必须以这种方式包括jQuery(最好不要问:P)

,而不是使用:


看一看这个问题。谢谢,但它没有帮助。加载过程和功能正在工作。以防万一,它不起作用。也检查一下答案。
function includeJSLib(lib, id, callback) {
  if (!document.getElementById(id)) {
    var s = document.createElement('script');
    s.setAttribute('id', id);
    s.setAttribute('async', 'false');
    s.setAttribute('type', 'text/javascript');
    s.src = lib;
    document.getElementsByTagName('head')[0].appendChild(s);
    var loaded = false;
    s.onload = s.onreadystatechange = function() {
      var readyState = this.readyState || 'complete';
      if (!loaded && ('loaded' === readyState || 'complete' === readyState)) {
        loaded = true;
        // Handle memory leak in IE
        s.onload = s.onreadystatechange = null;
        s.parentNode.removeChild(s);
        callback();
      }
    };
    // s.onload = callback;
  } else {
    callback();
  }
}
includeJSLib('https://code.jquery.com/jquery-1.11.3.min.js', 'jqueryInclude', function() {
  jQuery(document).ready( function($) {
    if ($('body').hasClass('class')) { do something }
  });
});