jquery clone最后一行表有排除

时间:2012-10-17 16:24:57

标签: jquery find clone

我有一个输入表,它的最后一行是:

    <tr>
        <td>
           <input type="hidden" value="" readonly="" size="3" name="id[]">
       </td>
<td>
      <input type="hidden" value="" readonly="" size="3" name="fkcommand[]">
      </td>
<td>
<select name="type[]">
<option value="C" selected="selected">C</option>
<option value="P">P</option></select>
</td>
<td>
  <input type="input" value="1200" size="6" name="strike[]">
</td><td>
      <input type="input" value="-2" size="6" name="quantity[]">
    </td>
    </tr>

我想要克隆这个输入行,清空它的值除了隐藏值fkcommand ,并将其附加到表的末尾

我正在使用它:

var row = $(this).parent().find('table tbody tr:last');
row.clone().find('input').val('').end().insertAfter(row).find('[name=fkcommand[]]').val('222');

不会将值'222'添加到fkcommand

2 个答案:

答案 0 :(得分:1)

问题可能在选择器中。引用属性值更好:

.find("[name='fkcommand[]']")

但是,我建议您以这种方式重写代码:

row.clone().insertAfter(row).find("input").each(function() {
    this.value = this.name == "fkcommand[]" ? "222" : "";
});

答案 1 :(得分:0)

这里你去了

var clonedRow = $(table).last('tr').clone();