<body>
<input type="button" />
<input type="button" />
<input type="button" />
<input type="button" /><input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" /><input type="radio" name="a" />
<input type="radio" name="a" />
</body>
如何只获取type为text类的 控件元素对象呢 ? 求教?

解决方案 »

  1.   

    <input type="button" />
    <input type="button" />
    <input type="button" />
    <input type="button" /><input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" /><input type="radio" name="a" />
    <input type="radio" name="a" />
    <script>
    var inps = document.getElementsByTagName('input'),
    len = inps.length,arr_text = [];

    for(var i = 0; i < len; i++){
    if(inps[i].type == 'text'){
    arr_text.push(inps[i]);
    }
    }


    alert('input属性type为text的有'+arr_text.length+'个');

    for(var j = 0; j < arr_text.length; j++){
    //楼主操作就行了``
    }
    </script>
      

  2.   


    或者给type="text"的控件一样的name="t"然后用document.getElementsByName('t');这样也行
      

  3.   

    最后一种方法就是根据id来查了。。document.getElementById("xxx")你懂的。。
      

  4.   


    或者给type="text"的控件一样的name="t"然后用document.getElementsByName('t');这样也行
      

  5.   

    木北北回答的真漂亮,楼主还有什么不满意的呢? 加个name是最简单的了。要不就用循环。
      

  6.   

    OK 收到  good desgin  多谢了~ 结贴!