2016-09-15 156 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。 –

回答

相关问题