请参阅此处的完整代码: jsfiddle/bBadM/ (这不适用于所有浏览器)在此先感谢。
Regards,
解决方案forEach 的mozilla/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach\">MDN文档包括使用方法的两个实现在实现JS早期版本的浏览器中。
我将在这里复制一个快速的(见完整链接):
if(!Array.prototype.forEach){ Array.prototype.forEach = function(fn,scope){ for i = 0,len = this.length; i< len; ++ i){ fn.call(scope,this [i],i,this); } } }
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: jsfiddle/bBadM/ (it´s not working with all browsers) Thanks in advance.
Regards,
解决方案The 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 complete 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); } } }
更多推荐
Javascript ForEach功能在IE中不起作用
发布评论