admin管理员组文章数量:1296893
how could I write the following Code that it is supported in all browsers? Because it seems that the forEach-Function is not supported in IE8...
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 );
} );
See the full Code here: / (it´s not working with all browsers) Thanks in advance.
Regards,
how could I write the following Code that it is supported in all browsers? Because it seems that the forEach-Function is not supported in IE8...
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 );
} );
See the full Code here: http://jsfiddle/bBadM/ (it´s not working with all browsers) Thanks in advance.
Regards,
Share asked Feb 12, 2013 at 7:18 SimonSimon 4672 gold badges12 silver badges31 bronze badges 3- Internet Explorer doesn't support "for each" loops. You will need to change the code to use regular for loops: – Rinku Commented Feb 12, 2013 at 7:20
- You can use pure javascript for loop for this, and jQuery are ending support of old browsers like IE8 – Taron Mehrabyan Commented Feb 12, 2013 at 7:21
-
4
Since you already use jQuery, use
$.each()
. – JJJ Commented Feb 12, 2013 at 7:21
1 Answer
Reset to default 10The MDN documentation for forEach
includes two implementations of the method for use in browsers that implement earlier versions of JS.
I'll reproduce the quick one (see the link for the plete one) here:
if ( !Array.prototype.forEach ) {
Array.prototype.forEach = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope, this[i], i, this);
}
}
}
本文标签: jqueryJavascript ForEach Function does not work in IEStack Overflow
版权声明:本文标题:jquery - Javascript ForEach Function does not work in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741621567a2388840.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论