<form action="test.php" method="post">
<input type="text" name="pic[]" value="1">
<input type="text" name="pic[]" value="4">
<input type="text" name="pic[]" value="5">
<input type="text" name="pic[]" value="4">
<input type="text" name="pic[]" value="5">
<input type="text" name="pic[]" value="6">
<input type="submit" value="提交" />
</form>

解决方案 »

  1.   

    function init(){
    var a={
    pic:1,
    picx:2
    }
    var str="{";
    var texts=document.getElementsByName("pic[]");
    for(var i=0;i<texts.length;i++){
    str+="pic"+i+":"+texts[i].value+",";
    }
    str=str.substring(0,str.length-1)+"}";
    var a=eval("("+str+")");
    for(var i in a){
    alert(i+":"+a[i]);
    }
    }
    window.onload=init;
    大体这样试试
      

  2.   

    不知道你想要哪种结果,两种方式都给你写了下。自己参考着用吧<input type="text" name="pic[]" value="1,"> 
    <input type="text" name="pic[]" value="4,"> 
    <input type="text" name="pic[]" value="5"> 
    <input type="text" name="pic[]" value="4"> 
    <input type="text" name="pic[]" value="5"> 
    <input type="text" name="pic[]" value="6"> <script type="text/javascript">
        var o=document.getElementsByName("pic[]");
        //1:将所有值归到一个属性中
        var arr=[];
        for(var i=0;i<o.length;i++){
            arr.push(escape(o[i].value));
        };
        var json={pic:arr.join(',')}
        //2:分开的键值对。通过索引对应
        var _json={};
        for(var i=0;i<o.length;i++){
            _json["pic"+i]=escape(o[i].value);
        };
        
        //方式一结果
        for(var i in json){
            alert(i+":"+json[i]);
        }
        //方式二结果
        for(var i in _json){
            alert(i+":"+_json[i]);
        }
    </script>