我一直在寻找这里在stackoverflow,发现许多批准的答案,但没有人可以帮助我。为什么jQuery append函数不附加表格?
所以,我基本上可以拿出这张桌子是代码
<table id="tableid" class="table table-responsive">
<thead>
<tr>
<th>header1</th>
<th>header2</th>
</tr>
</thead>
<tbody id="tbItems">
<tr>
<td>item1</td>
<td>item2</td>
</tr>
</tbody>
</table>
<button type="button" id="btnAddItem" onclick="addProduct">Add</button>
和这个js代码
var $tableS = $('#tableid');
function addProduct() {
$tableS.append("<tr><td>item2</td><td>item2</td></tr>");
}
,但我有0想法,为什么它不工作。 谢谢!
链接的jsfiddle:https://jsfiddle.net/LvvbLcn2/1/
'的onclick = “addProduct命令()”' – James
https://jsfiddle.net/LvvbLcn2/2/代码 –
你是在document.ready调用中还是在页面末尾运行代码?也不要使用内联JavaScript。 jQuery可以轻松创建事件处理程序。 – j08691