简体   繁体   English

如何动态地向表单添加输入字段

[英]How to dynamically add input fields to a form

I'm currently working with Asset Management system. 我目前正在使用资产管理系统。 The company is spread through out different locations. 该公司遍布不同地点。

This system can return asset items to store again if these items are not in use. 如果这些项目未被使用,该系统可以将资产项目再次存储。

What I want to do is return the item there are lots of items. 我想要做的是返回项目有很多项目。 So I have input fields like this: 所以我有这样的输入字段:

<td><input type="text" name="asset_id[]"/></td>
<td><input type="text" name="batch_code[]"/></td>
<td><input type="text" name="description[]"/></td>
<td><input type="text" name="status[]"/></td>
// current condition of the item

I can't use these fields again and again, I don't know how many fields are required for each particular situation. 我不能一次又一次地使用这些字段,我不知道每种特定情况需要多少字段。

If I can give an option to the user to add input fields if he/she needs, how do I do this. 如果我可以为用户提供一个选项,如果他/她需要添加输入字段,我该怎么做。

在这里你可以看到像http://jsfiddle.net/damian_silvera/ATzne/这样的东西

Using JS/jQuery propably : 可以使用JS / jQuery:

HTML : HTML:

   <a href="#" id="plus_row">Add Row</a>

jQuery jQuery的

$(document).ready(function(){
   $("a#plus_row").click(function(){
     $("table#form_table").append($("table#form_table").find('tr').get(0));
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM