我使用一个函数来克隆带有输入字段的 html 表格行,以允许用户进行多个输入。
我的html看起来像这样
<table id="ID_1">
<tr id="tr_id1">
<td><input type="hidden" value="databaseid"/></td>
<td>Inputfield 1</td>
<td>Inputfield 2 </td>
</tr>
</table>
<button onclick="cloneRow('ID_1', 'tr_id1')"></button>
和我的javascript
function cloneRow(tablename,rowname) {
var row = document.getElementById(rowname); // find row to copy
var table = document.getElementById(tablename); // find table to append to
var clone = row.cloneNode(true); // copy children too
clone.id = "newID"; // change id or other attributes/contents
table.appendChild(clone); // add new row to end of table
$('.pickDate').each(function() {
$(this).datepicker({ dateFormat: 'dd.mm.yy' });
});
}
为了在下一页上进行进一步的工作,我只需要第一个 <td><input type="hidden" value="databaseid"/></td>
因此,通过复制,它应该只复制隐藏的输入,但如果没有侧面的值,值应该看起来像 value=""
如何解决这个问题? (可以使用jQuery)
最佳答案
$(row).find('input:hidden').val('')
在函数调用后使用上面
关于javascript - 克隆行时清除隐藏输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26304803/