2014-04-04 49 views
1

我的腳本似乎在firefox和chrome上工作正常,但它似乎在ie8上失敗。 Stragely我在腳本中的所有代碼之前放置了一個alert函數,並且alert函數有效。但是document.ready函數幾乎從不執行。 這是一個ie8問題?如果是的話,我該如何解決這個問題? 請幫忙。jquery腳本在Chrome瀏覽器上工作正常,但不是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> 
+0

你可以請檢查,哪一行代碼在IE8中引發JS錯誤?您可以使用開發人員工具的腳本控制檯窗口來檢查它。 –

+2

如果我沒記錯的話,如果你在ie8 – pathfinder

+0

上使用console.log()奇怪地沒有錯誤,你的腳本將會失敗。代碼停止工作。我也注意到它在我打開控制檯後有效 –

回答

0

面對完全相同的情況曾經在我的應用程序。沒有錯誤,但代碼不會運行,除非你打開開發工具。而罪魁禍首就是那個console.log聲明。評論/刪除該console.log語句,它應該工作正常

+0

是啊! IE很奇怪!從來沒有面對這與其他瀏覽器 –

+0

奇怪?它f ****刺激性。這幾乎花了我整整一天的時間來弄清楚。令人驚訝的是,該控制檯僅在一個主幹路由器的初始化功能中出錯,代碼其他部分的控制檯正常工作。這是我們大多數人討厭IE:P –

+0

是啊!的SharePoint + IE8 =死亡 –

相關問題