<input id="post_points_1" type="text" name="post_points[1]" value="0">
<input id="post_points_2" type="text" name="post_points[2]" value="2">
<input id="post_points_3" type="text" name="post_points[3]" value="3">
<input id="post_points_4" type="text" name="post_points[4]" value="0">
<input id="post_points_5" type="text" name="post_points[5]" value="4">
<input id="post_points_6" type="text" name="post_points[6]" value="0">
<input id="post_points_7" type="text" name="post_points[7]" value="0">id ,name 都是动态生成的 怎么获得一个value的数组

解决方案 »

  1.   

    还有 找他们的父标签 如:<div id="xxx"><input></input></div> 直接获取xxx下的input就好了
      

  2.   

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script>
    function xx(){
    var xxxx = document.getElementById("xxx");
    var post_point = xxxx.getElementsByTagName("input");
    var post_point_l = post_point.length;
    var post_point_value = new Array() ;
    for( i =0; i<post_point_l; i++){
    post_point_value[i]=post_point[i].value;
    }
    alert(post_point_value)
    }
    </script>
    </head><body onLoad="xx()"><div id="xxx">
    <input id="post_points_1" type="text" name="post_points[1]" value="0">
    <input id="post_points_2" type="text" name="post_points[2]" value="2">
    <input id="post_points_3" type="text" name="post_points[3]" value="3">
    <input id="post_points_4" type="text" name="post_points[4]" value="0">
    <input id="post_points_5" type="text" name="post_points[5]" value="4">
    <input id="post_points_6" type="text" name="post_points[6]" value="0">
    <input id="post_points_7" type="text" name="post_points[7]" value="0">
    </div>
    </body>
    </html>- -真想鄙视你 都拿到元素了 都不敢动下脑筋拿值
      

  3.   


    谢啦 有没有 id 对应的值  想一个key 对应一个value的数组
      

  4.   

    name是动态生成  但是不要用索引都用一样的 名称
      

  5.   

    你的ID不是有顺序的么 要不再搞个数组: post_point_id[i]=post_point[i].id; post_point_id[i]就和post_point_value[i]对应了  还是你想通过id获取value 没理解你说啥意思
      

  6.   

    如果input放在div中的话,可以这样   document.getElementById("div id").getElementsByTagName("input"),剩下的操作楼上的几位讲的比较清楚了...