我使用函數來克隆帶有輸入字段的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的可以使用)
小提琴http://jsfiddle.net/21sv1bug/
正確縮進代碼,如果可能的話提供小提琴(http://jsfiddle.net/) – 2014-10-10 17:24:51
@NitsanBaleli我只是照顧的縮進...另一方面,我看不出有什麼理由,爲什麼這應該是一個問題沒有小提琴測試... – webeno 2014-10-10 17:27:05
@NitsanBaleli http://jsfiddle.net/21sv1bug/ – 2014-10-10 17:28:40