获取页面中name相同的input或者select标签的option值
<html>
<head><script>
function click_(){
var str = document.all.input1;
for(var i = 0; i< str.length ;i++){
console.log(str[i].value);
}
}
</script>
</head>
<body>
<input type ="text" name ="input1" value="1"/>
<input type ="text" name ="input1" value="2"/>
<input type ="text" name ="input1" value="3"/>
<input type ="text" name ="input1" value="4"/>
<input type ="text" name ="input1" value="5"/>
<input type ="text" name ="input1" value="6"/>
<button type="button" onclick="click_()">获取value值</button>
</body
</html>
效果如图:
本文是我在一个论坛看到的,然后自己做了实验,确实是不错的方式,所以类型是转载
希望对大家有帮助!!!