<分区>
我正在尝试通过我在 jQuery 中添加的类名来定位一个元素。如果我添加一个新元素,这似乎工作正常,但我无法让新事件绑定(bind)到 DOM 中已经存在但已更改的元素。
我做错了什么?
$(document).ready(function(){
$(".activateRow").on("click",function(){
$(this).text('Deactivate').addClass('deactivateRow btn-danger').removeClass('activateRow btn-success');
$(this).parent().parent().removeClass('inactiveRow');
});
$(".deactivateRow").on("click",function(){
$(this).text('Activate').removeClass('deactivateRow btn-danger').addClass('activateRow btn-success');
$(this).parent().parent().addClass('inactiveRow');
});
})