<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类的 控件元素对象呢 ? 求教?
<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>
或者给type="text"的控件一样的name="t"然后用document.getElementsByName('t');这样也行
或者给type="text"的控件一样的name="t"然后用document.getElementsByName('t');这样也行