js 如何获取表单提交的数组

js 如何获取表单提交的数组,第1张

直接用js里的getElementsByName就可以获取所以name值相同的元素。但获取出来的并不是数组,而是类数组的元素集合。所以还需要一步变换,下面是简单代码:

<body> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> <input type="text" name="111" /> </body> <script> var oInp = documentgetElementsByName('111'); var aInp = []; for(var i=0;i<oInplength;i++){ aInppush(oInp[i]); } </script> //这样aInp这个数组里存储的就是所以元素name为111的数组。

我给个例子给你吧:

<script>

    function he(){

     var file=documentgetElementById("haa")files[0];

     consolelog(file); 

     alert(file['name']);

    }

    

</script>

</head>

    <body>

      <input type="file" id="haa" onchange="he()"/>

    </body>

</html>

<form:select path="planId" class="input-xlarge"> 最后会生成正常的H5 标签,只要你的属性里配置了就会在生成的标签里附带又id值,然后用js根据id值取值即可:

var val = documentgetElementById(id)value;val就是你要取的标签的value。

以上就是关于js 如何获取表单提交的数组全部的内容,包括:js 如何获取表单提交的数组、JS怎么获取表单file的值、js 如何获取<form:form>表单某个值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9303538.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存