當前位置:編程學習大全網 - 腳本源碼 - js代碼怎麽得到window.document.getElementsByTagName("input")的所有value

js代碼怎麽得到window.document.getElementsByTagName("input")的所有value

思路:需要用到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>

  • 上一篇:電視劇親媽劉威葳
  • 下一篇:韓國知事是什麽官位
  • copyright 2024編程學習大全網