2013-10-29 38 views
0

请参阅以下JavaScript。这适用于除IE以外的所有其他浏览器。在IE Compat模式下,必须启用它才能工作。任何想法为什么?我相信它与indexOf有关。Javascript只能在IE兼容模式下工作

var styles = iDoc.find("head style[id$='ReportControl_styles']").html(); 
      if ((styles == undefined) || (styles == '')) { 
       iDoc.find('head script').each(function() { 
        var cnt = $(this).html(); 
        var p1 = cnt.indexOf('ReportStyles":"'); 
        if (p1 > 0) { 
         p1 += 15; 
         var p2 = cnt.indexOf('"', p1); 
         styles = cnt.substr(p1, p2 - p1); 
        } 
       }); 
      } 
      if (styles == '') { alert("Cannot generate styles, Displaying without styles.."); } 
      styles = '<style type="text/css">' + styles + "</style>"; 
+1

请打开开发人员控制台并查找任何错误。 – ComFreek

+0

使用此[链接](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf?redirectlocale=zh-CN&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FArray%2FindexOf )它可能对你有帮助。 – John

+0

你使用什么IE版本? IE版本<9没有indexOf – pax162

回答

0

目前,我已经从页面中删除了文档类型,并且还添加了所有工作正常。