我有以下 jQuery 代码:
$('#btnAdd').click(function() {
var i = ($('#stuff >tbody >tr').length)+1;
$('#stuff >tbody >tr:last').clone(true).find("input,select").each(function(){
$(this).attr({
'name': function(_, name){
return name + i;
},
'value': ''
});}).end().insertAfter('#stuff >tbody>tr:last').show();
这会产生以下 DOM:
<tr>
<td class="td_6">
<select name="name1">
<option selected="" value="Bricklayers">Bricklayers</option>
<option value="Sheet Metal Workers">Sheet Metal Workers</option>
<option value="Sprinkler Fitters">Sprinkler Fitters</option>
</select>
<td>
<td class="td_6">
<input name="V_union" value="1" type="radio">Yes<input name="V_union" value="0" type="radio" checked="checked">No
</td>
<td class="td_6">
<input name="V_picketed" value="1" type="radio">Yes<input name="V_picketed" value="0" type="radio" checked="checked">No
</td>
<td>
</td>
</tr>
<tr style="">
<td class="td_6">
<select name="name13" value="">
<option selected="" value="Bricklayers">Bricklayers</option>
<option value="Sheet Metal Workers">Sheet Metal Workers</option>
<option value="Sprinkler Fitters">Sprinkler Fitters</option>
</select>
</td>
<td class="td_6">
<input name="V_union3" value="" type="radio">Yes<input name="V_union3" value="" type="radio" checked="checked">No
</td>
<td class="td_6">
<input name="V_picketed3" value="" type="radio">Yes<input name="V_picketed3" value="" type="radio" checked="checked">No
</td>
<td>
</td>
</tr>
这是表单标签:
<form method="post" action="view_job.php" name="updateViolations" enctype="multipart/form-data">
动态输入的行在标签内。
当我在 $_POST 上执行 var_dump 时,我没有在 $_POST 变量中看到新的动态生成的表单输入。
我检查了其他几个问题,看来我做的一切都是正确的,但我迷路了。