我正在尝试通过 jQuery 动态添加表格行。一切正常,但该行不会将自身添加到最后一个 <tr>。相反,它将自身添加到 <table>...
我很困惑。谁能帮帮我?这是代码
Javascript
var counterx = 2;
var counter = 2;
$(document).ready(function(){
$("#addMoreRcpt").click(function(){
if (counterx>10){
alert("Only 10 reciepients are allowed");
return false;
}
var newTextBoxDiv = $(document.createElement('div')).attr("id", 'RcptEml_' + counter);
newTextBoxDiv.append("<tr><td>New Data</td><td>New Data</td><td>New Data</td></tr>");
newTextBoxDiv.appendTo("#RcptGroup");
counter++;
counterx++;
});
});
function fncDelRcpt(id){
$("#RcptEml_"+id).remove();
counterx--;
}
HTML
<table border=1>
<div id="RcptGroup">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<div id="1">
<tr>
<td>data</td>
<td>Data</td>
<td>data</td>
</tr>
</div>
</div>
</table>
<br /><a id="addMoreRcpt" href="#" >Add more reciepients</a>