簡體   English   中英

如何將箭頭 function 更改為正常的 function 以使其在 Internet Explorer 中工作?

[英]How to change arrow function to normal function that it works in Internet explorer?

我在 chrome 和 firefox 上使用以下代碼。

它運行良好,但由於 javascript 中有兩個箭頭 function,動畫在 Internet Explorer 上不起作用。

我應該如何在 javascript 中將它們寫成正常的 function?

提前致謝

您可以在這里找到一個演示https://jsfiddle.net/80vr25zf/

const counters = document.querySelectorAll('.evyt_.h-counter');    
counters.forEach(counter => {
const updateCount = () => {
const target = +counter.getAttribute('data-target');
const count = +counter.innerText;   

根據此頁面http://kangax.github.io/compat-table/es6/ , IE 11 中未實現 ES6 功能(包括箭頭和匿名函數)。

所以你應該使用 ES5 支持的經典 function 聲明(因此是 Internet Explorer)

您的代碼將如下所示:

const counters = document.querySelectorAll('.evyt_.h-counter');    
counters.forEach(function counterFunction(counter) {
const updateCount = function updateCode() {
const target = +counter.getAttribute('data-target');
const count = +counter.innerText;  }} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM