[英]Get value array in javascript
How to get value in javascript when input name/id generated by looping, just like this. 像这样通过循环生成输入名称/ id时,如何在javascript中获取值。
name="items[1AV08EBfeb][srdnReqQty1AV08EBfeb]"
--js--
var form = document.forms[0];
var get = form.items[1AV08BBjan][srdnReqQty1AV08BBjan].value;
alert(get); //error missing ]
--js--
Any suggestion ? 有什么建议吗?
Thanks 谢谢
MRizq MRizq
If the name of the element really is 如果元素的名称确实是
name="items[1AV08EBfeb][srdnReqQty1AV08EBfeb]"
...as you've shown, then: ...如您所示,然后:
var form = document.forms[0];
var get = form.elements["items[1AV08EBfeb][srdnReqQty1AV08EBfeb]"].value;
There's nothing special about the [
and ]
characters within the name
attribute of a form element at the HTML and JavaScript level. 在HTML和JavaScript级别,表单元素的name
属性中的[
和]
字符没有什么特别的。 Some server-side technologies (like PHP) will look for those characters in the names of submitted form fields and turn them into arrays, but that's not an HTML or JavaScript thing. 一些服务器端技术(例如PHP)会在提交的表单字段的名称中查找这些字符并将它们转换为数组,但这不是HTML或JavaScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.