我有这个:
<table>
<tr id="firstaut">
<td>Author:</td>
<td>
<input class="auts" name="name" />
</td>
<td>
<button class="aut_button" type="button">delete</button>
</td>
</tr>
<tr>
<td colspan="2">
<a onclick="addmore()"> + add more name</a>
</td>
</tr>
</table>
$(function(){
$('.aut_button').on('click',function(){
alert('test');
});
});
function addmore(){
$("<tr id='firstaut'><td>Author:</td><td><input class='auts' name='name'/></td><td><button class='aut_button' type='button'>delete</button></td></tr>")
.insertAfter('#firstaut').delegate('.aut_button');
}
如果我点击新添加的delete
按钮,则不是alerting
。我究竟做错了什么?
答案 0 :(得分:2)
尝试将on
与其他重载一起使用
$(function(){
$('table').on('click', '.aut_button' ,function(){
alert('test');
});
});
请阅读here以了解有关event delegation
的更多信息。