【发布时间】:2013-01-27 10:56:18
【问题描述】:
如何编写所有浏览器都支持的以下代码? 因为好像IE8不支持forEach-Function...
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/(并非适用于所有浏览器) 提前致谢。
问候,
【问题讨论】:
-
Internet Explorer 不支持“for each”循环。您需要更改代码以使用常规 for 循环:
-
你可以使用纯 javascript for 循环来实现这个,jQuery 正在停止支持像 IE8 这样的旧浏览器
-
既然你已经用过jQuery,那就用
$.each()吧。
标签: javascript jquery function internet-explorer-8 foreach