更新时间:2023-12-03 22:14:40
如果你是在jQuery的1.7+然后用在
或委托
来代替。它比老方法更有效。在这里,我监测的表格单元格单击事件表。当事件发生时我加入点击!
表格单元格。这既适用于初始表单元格并添加的。
If you are in jQuery 1.7+ then use on
or delegate
instead. It is more efficient than old methods. Here I monitor the table for click events on table cells. When an event occurs I add clicked!
to the table cell. This works for both the initial table cells and added ones.
$('#more').change(function(e) {
for (var i = 0; i < $(this).val(); i++) {
$('#myTable').append('<tr><td></td></tr>');
}
});
$('table').on('click', 'td', function() {
$(this).html('clicked!');
});