name相同获取值

<html>  
<head>  
</head>  
<body>  
<form name="form1" method="post" action="" >  
<p>  
<input type="text" name="plan_bm_num[]"  id="plan_bm_num[]" value="1">,  
<input type="text" name="plan_bm_num[]"  id="plan_bm_num[]"  value="2">,  
<input type="text" name="plan_bm_num[]"  id="plan_bm_num[]" value="3">,  
<input type="text" name="plan_bm_num[]"  id="plan_bm_num[]" value="4">  
</p>  
  <p>  
    <label for="plan_total_renshu"></label>  
    <input type="text" name="plan_total_renshu" id="plan_total_renshu">  
  </p>  
  <p>  
    <input type="button" name="button" id="button" value="按钮" onClick="check();">  
  </p>  
</form>  
</body>  
</html>
<script language="javascript">  
function check(){  
    var bm_num=0;  
    var names =document.getElementsByName("plan_bm_num[]"); 
    for(i=0;i<names.length;i++){  
    value=names[i].value;   
    console.log(value);
    }
}  
</script>  

 

posted on 2017-12-18 13:25  薇薇123456  阅读(100)  评论(0编辑  收藏  举报

导航