思路:需要用到js的循環,使用for循環即可;
先用getElementsByTagName獲取到所有的input標簽,再用for循環獲取到所有的value。
代碼如下:
<input?type="text"?value="a"?/>//放上去壹個input<input?type="text"?value="b"?/>
<input?type="text"?value="c"?/>
<input?type="text"?value="d"?/>
<input?type="text"?value="e"?/>
<input?type="text"?value="f"?/>
<input?type="text"?value="g"?/>
<input?type="text"?value="h"?/>
<script>
var?oinput=document.getElementsByTagName('input');//獲取到所有的input
for(i=0;i<oinput.length;i++){//開始for循環
alert(oinput[i].value);
}
</script>