<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>
<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>
解决方案 »
- 静态页面上传到空间后JS失效,望高手解答
- jquery问题,求教高手
- 请问一个java脚本的问题!
- event.contentOverflow 获取表明文档处理当前 LayoutRect 对象后是否包含附加的内容。
- 散分,发个好玩的~~怎么看盗链的图片~
- fckeditor设置菜单默认状态是折叠的,怎么设置?谢谢!
- onSubmit不起作用?谢谢!
- 怎么样得到控件数组内容?
- 一个页面中嵌入了两个iframe,每个iframe里面有几个input,如何在这个页面中判断iframe中的input是否为空?javascript该如何写啊?
- 如何触发一个事件后让marquee再走一次
- js实现图片layz loading的原理?
- js 怎么让事件1 去执行事件2
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;
大体这样试试
<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>