当选着删除按钮的时候,我们一般都会使用confirm属性
```
// 删除按钮事件
$("#remove").on("click", function() {
if (!confirm("是否确认删除?"))
return;
var rows = $("#mytab").bootstrapTable('getSelections');// 获得要删除的数据
if (rows.length == 0) {// rows 主要是为了判断是否选中,下面的else内容才是主要
/* alert("请先选择要删除的记录!"); */
layer.msg('请先选择要删除的记录!', {
icon : 5,
time : 1000
});
return;
} else {
var ids = new Array();// 声明一个数组
$(rows).each(function() {// 通过获得别选中的来进行遍历
ids.push(this.id);// cid为获得到的整条数据中的一列
});
deleteMs(ids);
}
})
function deleteMs(ids) {
$.ajax({
url : basePath + "/dels/callerAlarm",
data : "ids=" + ids,
type : "get",
dataType : "json",
success : function(data) {
$('#mytab').bootstrapTable('refresh', {
url : basePath + '/list/callerAlarm'
});
}
});
}
```
但是效果是这样的,太过于简单,现在要搭配layer样式来改变一下样式
其实代码很简单
```
// 删除按钮事件
$("#remove").on("click", function() {
var rows = $("#mytab").bootstrapTable('getSelections');// 获得要删除的数据
if (rows.length == 0) {// rows 主要是为了判断是否选中,下面的else内容才是主要
/* alert("请先选择要删除的记录!"); */
layer.msg('请先选择要删除的记录!', {
icon : 5,
time : 1000
});
return;
} else {
layer.confirm("确认要删除吗,删除后不能恢复", { title: "删除确认" }, function (index) {
var ids = new Array();// 声明一个数组
$(rows).each(function() {// 通过获得别选中的来进行遍历
ids.push(this.id);// cid为获得到的整条数据中的一列
});
deleteMs(ids);
layer.close(index);
});
}
})
function deleteMs(ids) {
$.ajax({
url : basePath + "/dels/staffAlarm",
data : "ids=" + ids,
type : "get",
dataType : "json",
success : function(data) {
$('#mytab').bootstrapTable('refresh', {
url : basePath + '/list/staffAlarm'
});
}
});
}
```
原文链接:https://blog.csdn.net/qq_36538012/article/details/10051735
改完之后,如果样式不满意,可以继续修改。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有