<table id="mytable">
<tr id="gonnaclone">
<td>
<input type="text" id ="isim" name="f1" class="large" value = "" />
</td>
<td>
<input type="checkbox" id ="komut" name="f2" checked/>
</td>
</tr>
</table>
我正在尝试克隆表格行,但它带有与克隆行相同的值。
var table = document.getElementById("mytable");
var row = document.getElementById("gonnaclone");
var clone = row.cloneNode(true);
table.appendChild(clone);
我尝试了 row.cloneNode(false);
但它停止工作了。
如何让克隆行的值为空?
最佳答案
你可以这样做
var table = document.getElementById("mytable");
var row = document.getElementById("gonnaclone");
var clone = row.cloneNode(true);
/**
Will Ensure that blank entry are appended in html
**/
var InputType = clone.getElementsByTagName("input");
for (var i=0; i<InputType.length; i++){
if( InputType[i].type=='checkbox'){
InputType[i].checked = false;
}else{
InputType[i].value='';
}
}
table.appendChild(clone);
关于javascript - 复制没有值的表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21873710/