黄聪:jquery.confirm弹出确认消息

时间:2023-03-09 09:14:44
黄聪:jquery.confirm弹出确认消息

1、插件介绍

该确认框的默认样式如:

黄聪:jquery.confirm弹出确认消息

1.1、插件默认参数

// 默认参数
$.confirm.defaults = {
// 样式
css: "http://static.qianduanblog.com/css/jquery.confirm/default.min.css?v=" + Math.ceil(new Date() / 86400000),
// 确认框内容
content: "确认吗?",
// 确认按钮文字
sureButton: "确认",
// 取消按钮文字
cancelButton: "取消",
// 位置
position: {},
// 自动打开
autoOpen: false,
// 动画持续时间
duration: 123,
// 打开确认框回调
onopen: emptyFn,
// 单击了确认或者取消回调
onclick: emptyFn,
// 确认回调
onsure: emptyFn,
// 取消回调
oncancel: emptyFn,
// 关闭确认框回调
onclose: emptyFn
}

1.2、插件结构与样式

jquery.confirm的dom结构为:

<div class="jquery_confirm____" style="display:none">
<div class="jquery_confirm____body">确认框消息</div>
<div class="jquery_confirm____footer">
<button class="button button-primary jquery_confirm____sure">确认</button>
<button class="button button-error jquery_confirm____cancel">取消</button>
</div>
</div>

默认的插件样式基于css.3(详细:http://festatic.aliapp.com/css/3/latest.min.css),默认的插件样式地址为default(详细:http://festatic.aliapp.com/css/jquery.confirm/default.min.css),插件样式只渲染一次,不会多次渲染,以第一次使用插件的样式为准。

1.3、使用方法

// 打开确认框
$.confirm({
content: "确认要查看吗?",
onopen: function() {
alert("确认框打开了!");
},
onclose: function() {
alert("确认框关闭了!");
},
onsure: function() {
alert("你单击了确认按钮!");
},
oncancel: function() {
alert("你单击了取消按钮!");
},
onclick: function(s) {
if (s) {
alert("你单击了确认按钮!");
} else {
alert("你单击了取消按钮!");
}
}
}); $.confirm("确认吗?", function(s) {
if (s) {
alert("你单击了确认按钮!");
} else {
alert("你单击了取消按钮!");
}
});

2、插件demo及下载

原文:http://qianduanblog.com/post/jquery-plugin--jquery-confirm.html