2016-09-15 153 views
-2

我有一小部分代碼在Chrome中正常工作,沒有錯誤。在Internet Explorer中運行時出現語法錯誤,但我對這些差異不夠熟悉,無法知道導致錯誤的原因。在IE瀏覽器11中Javascript語法錯誤,但在Chrome中沒問題

sleep(1000).then(() => { 
      resetTDcolor(SRID) 
      }); 

錯誤在上面的代碼的第一行顯示。睡眠功能和復位功能在以下情況下可以幫助。

function sleep (time) { 
     return new Promise((resolve) => setTimeout(resolve, time)); 
    } 

    function resetTDcolor(SRID){ 
     var SR = document.getElementsByClassName('scoutRequirement' + SRID); 
     for (i=0;i<SR.length;i++){ 
     SR[i].style.backgroundColor = ''; 
     } 
    } 

任何幫助或澄清將不勝感激。

+2

Internet Explorer並不真正支持[ES6 arrow](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions)函數,您必須將其重寫爲'function (resolve){setTimeout(resolve,time); }'。我甚至不確定Internet Explorer是否有Promise的基本支持 – Icepickle

+0

看看這裏https://kangax.github.io/compat-table/es6/ IE 11不支持箭頭功能 重寫它或使用babel fe –

+0

或者你可以使用babel。 –

回答

相關問題