请从adeneo 的这个答案中参考这个小提琴。
这一直有效,直到几个月前 jquery 中的一些更改必须破坏它。它在我的网站和上面链接的小提琴中坏了。
这是html和jquery:
$(function() {
$('#processname').on('click', '.addRow', function() {
var body = $(this).closest("tbody");
var row = $(this).closest("tr");
var newNum = $(".operation").length + 1;
var clone = row.clone();
clone.find('.rowNumber').html(newNum);
body.append(clone);
});
});
<form id="processname" name="processname" method="post" action="" >
<table border="1" width="50%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="right" valign="middle">Order</td>
<td align="left" valign="middle">Process</td>
<td>Operation</td>
<td>Value</td>
<td>+</td>
<td>–</td>
</tr>
<tr>
<td><span class="rowNumber">1</span></td>
<!--<td><span class="rowNumber">1</span></td>-->
<td>
<select class="process" name="category_1" id="category_1" onChange="javascript: dropdownlist(this); elementPos(this)">
<option value="">Select Category</option>
<option value="3" selected="selected">translate</option>
<option value="4">math</option>
<option value="5">format</option>
<option value="6">write</option></select>
</td>
<td align="left" valign="middle">
<select class="operation" name="operation_1" id="operation_1">
<option value="">Select Sub-Category</option>
<option value="s->c" selected="selected">Use source as core by default</option>
<option value="s->t->c">Only process translated values</option>
</select>
</td>
<td>
<input type="text" name="value_1" id="value_1" value="" />
</td>
<td><input type="button" style="max-width:5em" class="addRow" value="+" /></td>
<td><input type="button" class="delRow" value="-" /></td>
</tr>
</table>
</form>