【发布时间】:2017-12-26 05:29:18
【问题描述】:
我正在尝试从“td”内的输入字段中读取数据,ID 在“tbody”内
html结构是这样的:
<tbody id="tbody1">
<tr>
<td>
<input type="text" id="bacthNo" class="form-control md-has-value" required="">
</td>
<td>
<input type="text" id="location" class="form-control md-has-value" required="">
</td>
<td>
<input type="text" id="qty" class="form-control md-has-value" required="">
</td>
</tr>
<tr>
<td>
<input type="text" id="bacthNo" class="form-control md-has-value" required="" value="0">
</td>
<td>
<input type="text" id="location" class="form-control md-has-value" required="" value="0">
</td>
<td>
<input type="text" id="qty" class="form-control md-has-value" required="" value="0">
</td>
</tr>
</tbody>
<tbody id="tbody2">
<tr>
<td>
<input type="text" id="bacthNo" class="form-control md-has-value" required="">
</td>
<td>
<input type="text" id="location" class="form-control md-has-value" required="">
</td>
<td>
<input type="text" id="qty" class="form-control md-has-value" required="">
</td>
</tr>
<tr>
<td>
<input type="text" id="bacthNo" class="form-control md-has-value" required="" value="0">
</td>
<td>
<input type="text" id="location" class="form-control md-has-value" required="" value="0">
</td>
<td>
<input type="text" id="qty" class="form-control md-has-value" required="" value="0">
</td>
</tr>
</tbody>
这里的“tbody”id 是动态变化的,每个“tbody”的 tr 可以在 1 到 10 之间。
我想要的是读取每个 tbody 的“bacthNo”、“location”和“qty”的所有数据,并在表单提交时推入一个数组。我尝试了几种方法,但无法从这种复杂的表单中获取数据。
请帮助。
【问题讨论】:
-
不要将
id用于<tbody>。只需为每个 tbody 使用相同的类,然后使用.each并获取所有内容。 (通过id也可以,但是代码有点复杂) -
你能给我同样的代码示例吗?这对我有帮助
标签: javascript jquery html css frontend