87,907
社区成员
发帖
与我相关
我的任务
分享
function process(){
alert('aaa');
};
window.onload = function(){
var oInputs = document.getElementsByTagName('input');
var array = ['a','b'];
chunk(oInputs,process); //这块传array数组就可以,传oInputs就不行报错!
};
function chunk(array,process,context){
var items = array.concat();
setTimeout(function(){
var ite = items.shift();
process.call(context,ite);
if(items.length > 0){
setTimeout(arguments.callee,100);
}
},100);
};
<input type="button" id="testx" value="aa" />
<input type="button" id="testy" value="bb" />
<input type="button" id="testz" value="cc" />
<input type="button" id="testa" value="dd" />
// 比如 arguments
<script type="text/javascript">
<!--
function Pro(){
alert([].slice.call(arguments));// or Array.prototype.slice.call(arguments)
}
Pro('1','2','3')
//-->
</script>
// 不好意思 我看错题
<script type="text/javascript">
<!--
var $A = function(coll){
if(coll.item){
var l = coll.length, array = new Array(l);
while (l--) array[l] = coll[l];
return array;
}
}
window.onload = function(){
var oInputs = document.getElementsByTagName('input');
alert($A(oInputs))
};
//-->
</script>
<input type="button" id="testx" value="aa" />
<input type="button" id="testy" value="bb" />
<input type="button" id="testz" value="cc" />
<input type="button" id="testa" value="dd" />
function chunk(array,process,context){
var items = Array.prototype.concat.call(array);
setTimeout(function(){
var ite = items.shift();
process.call(context,ite);
if(items.length > 0){
setTimeout(arguments.callee,100);
}
},100);
};
<script>
function process(){
alert('aaa');
};
function bind(grg){
Array.prototype.Function.call(grg);
}
window.onload = function(){
var oInputs = document.getElementsByTagName('input');
var array = ['a','b'];
alert(oInputs instanceof Array )
alert(array instanceof Array )
// chunk(oInputs,process); //这块传array数组就可以,传oInputs就不行报错!
oInputs.chunk=(function(process,context){
var items = Array.prototype.concat.call(this);
setTimeout(function(){
var ite = items.shift();
process.call(context,ite);
if(items.length > 0){
setTimeout(arguments.callee,100);
}
},100);
})(process)
};
</script>
<input><input>
var array = [];
var oInputs = document.getElementsByTagName('input');
for(var i = 0; i < oInputs.length; i++){
array.push(oInputs[i]);
}
chunk(array,process);
Array.prototype.slice.call(oInputs)
//这个方法为什么在IE下不支持呢?能解决吗?
Array.prototype.slice.call(oInputs)