简体   繁体   English

HTML表单未传递从jQuery动态添加的输入

[英]HTML Form not passing inputs added dynamically from jQuery

I'll keep it short and simple, I've browsed and browsed around here and other sites but am unable to find a solution for my issue: I've got an HTML form that works fine. 我会简单明了,我在这里和其他站点浏览和浏览,但是找不到解决我问题的方法:我有一个运行良好的HTML表单。 An update I'm doing allows the end user to add a new TR dynamically into a Table that will contain 4 input fields. 我正在做的更新允许最终用户向包含4个输入字段的表中动态添加新的TR。 Each input field has the name, id, and class set. 每个输入字段都有名称,ID和类集。 (This was one of the solutions from another posting.) There's a span the user clicks which creates the new TR with the inputs. (这是另一种发布的解决方案之一。)用户单击的跨度将使用输入创建新的TR。 The functionality of this works perfectly, and the new TR gets created and the inputs are there and do what I need them to. 此功能的工作原理非常完美,并且创建了新的TR,输入在那里,可以完成我需要的操作。 However, when I submit the form, it doesn't recognize the dynamically created inputs. 但是,当我提交表单时,它无法识别动态创建的输入。

I've debugged in both Chrome and FF, I can see all the other form elements being passed through, except for my dynamically created elements. 我已经在Chrome和FF中进行了调试,可以看到除动态创建的元素以外的所有其他表单元素。 The way I'm trying to reference the data on the receiving page is not the issue (Another solution for another user having the same issue,) since the data isn't being passed in the first place. 我尝试在接收页面上引用数据的方式不是问题(另一种解决相同问题的用户的解决方案),因为数据不是一开始就传递的。

If I serialize the form and alert it before submitting it, it does not pick up on the dynamically created elements. 如果我序列化表单并在提交表单之前发出警报,则它不会在动态创建的元素上出现。

Below is my jQuery code, any help would be greatly appreciated, and thanks in advance! 下面是我的jQuery代码,任何帮助将不胜感激,在此先感谢您!

var kit_rows = 0;
var btn_add_rows_i = 1;
var btn_add_rows_x = '';

$('#text_add_rows').click(function() {

kit_rows += 1;

btn_add_rows_x = '';
btn_add_rows_x += "<tr>";
    btn_add_rows_x += "<td class='main'> Model #: ";
    btn_add_rows_x += "<input type='text' name='kit_model" + btn_add_rows_i + "' id='kit_model" + btn_add_rows_i + "' class='kit_model'> &nbsp; </td>";

    btn_add_rows_x += "<td class='main'> Qty: ";
    btn_add_rows_x += "<input type='text' name='kit_qty" + btn_add_rows_i + "' id='kit_qty" + btn_add_rows_i + "' class='kit_info kit_qty'> &nbsp; </td>";

    btn_add_rows_x += "<td class='main'> Price: ";
    btn_add_rows_x += "<input type='text' name='kit_price" + btn_add_rows_i + "' id='kit_price" + btn_add_rows_i + "' class='kit_info kit_price' value='0.00'> &nbsp; </td>";

    btn_add_rows_x += "<td class='main'> Wholesale: ";
    btn_add_rows_x += "<input type='text' name='kit_wholesale" + btn_add_rows_i + "' id='kit_wholesale" + btn_add_rows_i + "' class='kit_info kit_wholesale' value='0.00'> &nbsp; </td>";
btn_add_rows_x += "</tr>";

$('#tr_last').before(btn_add_rows_x);

btn_add_rows_i++;

alert($('#cat').serialize());

});

My questions are: 我的问题是:

Once I $('#tr_last').before(btn_add_rows_x); 一旦我$('#tr_last')。before(btn_add_rows_x); the content, shouldn't the HTML form pick up on the content automatically? 内容,HTML表单不应该自动提取内容吗?

Does jQuery's "before" function do the job or is there something different I should be using that will allow the form to pick up on the new content? jQuery的“ before”功能能完成这项工作吗?或者我应该使用其他方式允许表单获取新内容吗?

have a look on this jsfiddle. 看看这个jsfiddle。 whether it satisfies your requirement 是否满足您的要求

enter code here http://jsfiddle.net/gurunathana/8eeqwhyf/ enter code here http://jsfiddle.net/gurunathana/8eeqwhyf/

Regret if i mistakenly understand your query. 遗憾,如果我错误地理解了您的查询。

Thanks, 谢谢,

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

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