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" />

解决方案 »

  1.   


    Array.prototype.slice.call(oInputs)
      

  2.   


    报错 说缺少JScript对象
      

  3.   

    准确的说 getElementsByTagName返回的节点列表类型 NodeList对象.
      

  4.   


    IE下用这方法报错 说缺少JScript对象
    FF下通过 没错
      

  5.   


    那应该怎么解决呢?
    我总觉得getElementsByTagName方法返回的是一个伪数组.
      

  6.   

    要么将集合中的元素,加入到一个Array()中,然后再对Array进行操作.
      

  7.   

                    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下不支持呢?能解决吗? 
      

  8.   

    在JS中getElementsByTagName()获得的是一个类似于数组的NodeList对象,但除了有个length属性和下标取值以外再也没有别的数组方法了,因为他不是一个真正的数组对象。
      

  9.   

    这样<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>
      

  10.   

    注意我代码中间alert(oInputs instanceof Array )
             alert(array instanceof Array )证明 确实不是个array对象后面我用了array来构造,可以用了,LZ看看
      

  11.   

    或者只改下面也OK的
     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);
        };
      

  12.   


    // 不好意思 我看错题
    <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" />
      

  13.   


    用你的方法 我只弹出一次 aaa 应该是4次~·
      

  14.   


    可以了~··我还想问你下~·你之前跟我说的那个方法怎么才能让它在IE下也支持呢?
    就是这个Array.prototype.slice.call(oInputs) 
      

  15.   


    我看错题目了 想当然给你写的....等回头一看 你是将Object类型转成数组... 
      

  16.   


    // 比如 arguments
    <script type="text/javascript">
    <!--
    function Pro(){
    alert([].slice.call(arguments));// or  Array.prototype.slice.call(arguments)
    } Pro('1','2','3')

    //-->
    </script>