您可以提交带有文本输入数组的表单吗? [英] can you submit a form with an array of text input?

查看:105
本文介绍了您可以提交带有文本输入数组的表单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态地建立一个页面.该页面需要从输入标签读取信息,但是它是动态的.我应该把东西设置为数组吗?

i am dynamically building a page. This page needs to read information from input tags but it is dynamic. Should i set up stuff to be an array since i am looking at

我想保留数据集.

<script>
   function adjustPilots(){
var pilots = $("#numPilots").val();
var info = '<td><table>'+
    '<tr><td>Minumum Collateral</td><td colspan="2"><input type = "text" size = "10" maxLength = "6" /> to <input type = "text" size = "10" maxLength = "6" /></td></tr>'+
    '<tr><td>Reward</td><td colspan="2"><input type = "text" size = "10" maxLength = "6" /> to <input type = "text" size = "10" maxLength = "6" /></td></tr>'+
    '<tr><td>Volume</td><td colspan="2"><input type = "text" size = "10" maxLength = "7" /> to <input type = "text" size = "10" maxLength = "7" /></td></tr>'+
    '<tr><td>Start: </td><td><input type = "text" name = "s" id = "s" class = "s" value autocomplete = "off"></td></tr>'+
    '<tr><td>End: </td><td><input type = "text" name = "e" id = "e" class = "e" value autocomplete = "off"></td></tr>'+
    '</table></td>';


for(var i = 0; i < Number(pilots); i++){
    $("#pilotrow").append(info);
}
}
</script>
<body>
<form>
<table>
<tr><td>Number of Pilots</td><td colspan="2"><input id = "numPilots" type = "text" size="3" maxLength="3" onchange = 'adjustPilots()' /></td></tr>
<tr id = "pilotrow"></tr>

<tr><td><input type = "submit" name = "submit"></td></tr>
</table>
</form>
</body>

我想的一个选择就是不使用表单,而是使用javascript构建表单.然后创建一个JSON对象,并使用AJAX将其发送到服务器.是这样做的可靠方法,还是有更好的主意?

An option i was thinking was to just not use a form, and build it with javascript. Then make a JSON object and use AJAX to send it to the server. Is that a solid way of doing it, or is there a better idea?

推荐答案

至少有两种方法可以做到这一点.

There are at least 2 way to do that.

没有javascript,您可以使用这样的元素数组来对表单进行分类

Without javascript, you cate a form with array of element like this

<input type="text" name="input[]"/>
<input type="text" name="input[]"/>
<input type="text" name="input[]"/>
<input type="text" name="input[]"/>

在php

$inputs = $_POST['input'];
for($inputs as $inp){

}

使用ajax和jquery,您可以简单地序列化表单并将其发布到后端

With ajax and jquery, you can just simply serialize your form and post to backend

这篇关于您可以提交带有文本输入数组的表单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆