【问题标题】:jquery script working fine on chrome but not ie8jquery 脚本在 chrome 上运行良好,但在 ie8 上运行良好
【发布时间】:2014-04-04 05:19:35
【问题描述】:

我的脚本似乎在 firefox 和 chrome 上运行良好,但在 ie8 上似乎失败了。 奇怪的是,我在脚本中的所有代码之前放置了一个警报功能,并且警报功能起作用。但 document.ready 函数几乎从不执行。 这是ie8的问题吗?如果是这样,那么我该如何解决这个问题? 请帮忙。

代码:

<script src="/_layouts/topsoe.common/js/jquery-1.10.2.min.js?rev=YoBy5yEtsejNrLIrIXUs2g%3D%3D" type="text/javascript"></script>
<script>
$(document).ready(function () {
    // hide the last two columns and their headings
    $("#WebPartWPQ3 .ms-vh2:eq(5)").css("display", "none"); // for the last two column headings;
    $("#WebPartWPQ3 .ms-vh2:eq(4)").css("display", "none");
    // for each row in the application page
    var idcount = 0;
    $("#WebPartWPQ3 .ms-itmhover").each(function () {
        var proj_ID='project' + idcount; // assigning each row an id so that they can be accesed individually
        $(this).attr('id', 'project' + idcount); 
        idcount = idcount + 1;
        $("#"+proj_ID+"  .ms-vb2:eq(5)").css("display", "none");
        $("#"+proj_ID+" .ms-vb2:eq(4)").css("display", "none");
        // extracting the project status and the precentage of completion. these will be used to assign color codes
        var status = $("#"+proj_ID+" .ms-vb2:eq(3)").html();
        var percentage = $("#" + proj_ID + " .ms-vb2:eq(5) div").html();
        var suffix = percentage.match(/\d+/);
        console.log(proj_ID + "\n" + status + "\n" + percentage); // remove after testing
        // formatting the status cell accroding to the status and percentage;
        var bg_color; var status_formatted;
        if (status == "In Progress") {
            $("#" + proj_ID + " .ms-vb2:eq(3)").html("<div style='position:relative; width:" + suffix + "%;background:#44AFF6; z-index:0; height:60px; margin-bottom:-50px;'></div><div style='position:relative; z-index:1; text-align:center; margin-left:2px;' >In Progress</br>" + percentage + "</div>");
        }
        if (status == "Completed") {
            $("#" + proj_ID + " .ms-vb2:eq(3)").html("<div style='position:relative; width:100% ;background:#57C759; z-index:0; padding:20px 2px; coor:black; height:23px; text-align:center'>completed</div>");
        }
        if (status == "Halted") {
            $("#" + proj_ID + " .ms-vb2:eq(3)").html("<div style='position:relative; width:" + suffix + "%;background:#FF0033; z-index:0; height:60px; margin-bottom:-50px;'></div><div style='position:relative; z-index:1; text-align:center; margin-left:2px;' >Halted </br> " + percentage + "</div>");
        }
        if (status == "User Acceptance Testing") {
            $("#" + proj_ID + " .ms-vb2:eq(3)").html("<div style='position:relative; width:100% ;background:#FFFF66; z-index:0; padding:20px 2px; coor:black; height:23px; text-align:center;'>UAT</div>");
        }
    });
});
</script>

【问题讨论】:

  • 你能检查一下,哪一行代码在IE8中抛出了JS错误?您可以使用脚本的开发者工具控制台窗口进行检查。
  • 如果我没记错的话,如果你在 ie8 上使用 console.log(),你的脚本会失败
  • 奇怪的是没有错误。代码只是停止工作。我也注意到打开控制台后它可以工作
  • “没有错误”???当代码中有console.log()s 时,您肯定会在IE8 中得到“Cannot find property log of undefined”,并且控制台未打开,尽管您在控制台中看不到该错误; )。
  • if(!console) {console={}; console.log = function(){};}

标签: jquery internet-explorer internet-explorer-8


【解决方案1】:

曾经在我的应用中遇到过完全相同的情况。没有错误,但除非您打开开发人员工具,否则代码不会运行。罪魁祸首是那个 console.log 声明。注释/删除该 console.log 语句,它应该可以正常工作

【讨论】:

  • 是的! IE很奇怪!!从未在其他浏览器中遇到过这种情况
  • 奇怪?它他妈的令人讨厌。我几乎花了一整天的时间才弄清楚这一点。令人惊讶的是,该控制台仅位于行为不端的骨干路由器的初始化功能中。代码其他部分的控制台工作正常。那就是我们大多数人讨厌 IE:P
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-25
  • 1970-01-01
  • 2014-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-22
相关资源
最近更新 更多