我有Datatable
和jquery插件删除此数据表的行
Jquery代码:
$(document).ready(function () {
$(".delete-ajax").live("click", function (e) {
e.preventDefault();
recordId = $(this).attr('id');
alert(recordId);
var requestAdress = '{!! route("admin.area.cities.destroy", ":id") !!}';
requestAdress = requestAdress.replace(':id', recordId);
$.ajax({
cache: false,
dataType: "json",
type: "delete"
, url: requestAdress
, date: {
"_token": "{{ csrf_token() }}",
"id": recordId
},
success: function () {
$('tr#' + recordId).fadeOut(300, 'linear');
}
}, "json");
});
});
代码工作没问题,但每当我在datatable
分页jquery插件中更改页面时。此点击不再有效。
数据表网站:http://datatables.net
答案 0 :(得分:1)
现在折旧使用.live()。使用事件委托:
$(document).ready(function () {
$(document).on("click",".delete-ajax", function (e) { // updated ths line
e.preventDefault();
recordId = $(this).attr('id');
alert(recordId);
var requestAdress = '{!! route("admin.area.cities.destroy", ":id") !!}';
requestAdress = requestAdress.replace(':id', recordId);
$.ajax({
cache: false,
dataType: "json",
type: "delete"
, url: requestAdress
, date: {
"_token": "{{ csrf_token() }}",
"id": recordId
},
success: function () {
$('tr#' + recordId).fadeOut(300, 'linear');
}
}, "json");
});
});