2
我如何编写以下支持所有浏览器的代码? 因为它似乎是的foreach功能在IE8支持...Javascript ForEach Function无法在IE浏览器中工作
digits.forEach(function(value, index) {
// create a span with initial conditions
var span = $('<span>', {
'class': 'digit0',
'data': {
'current': 0,
'goal' : value
}
});
// append span to the div#number
span.appendTo($('div#number'));
// call countUp after interval multiplied by the index of this span
setTimeout(function() { countUp.call(span); }, index * interval);
});
看到完整的代码在这里:http://jsfiddle.net/bBadM/(it's并不适用于所有浏览器中工作) 在此先感谢。
问候,
Internet Explorer不支持“对每个”循环。您需要更改代码才能使用常规循环: – Rinku 2013-02-12 07:20:40
您可以使用纯JavaScript进行循环,而jQuery将终止对IE8等旧浏览器的支持 – 2013-02-12 07:21:16
由于您已经使用jQuery,请使用['$ .each()' ](http://api.jquery.com/jQuery.each/)。 – JJJ 2013-02-12 07:21:25