jquery-confirm使用方法

简要教程

jquery-confirm是一款功能强大的jQuery对话框和确认框插件。它提供多种内置的主题效果,可以实现ajax远程加载内容,提供动画效果和丰富的配置参数等。它的特点还有:

  • 可以使用键盘控制对话框。
  • 通过ajax加载对话框的内容。
  • 可以在指定时间之后自动关闭对话框。
  • 提供丰富的参数和回调函数。

使用方法

基本调用
$.confirm({
    confirm: function(){
            console.log('the user clicked confirm');
    },
    cancel: function(){
            console.log('the user clicked cancel');
    }
});   

 

全局默认参数
jconfirm.defaults = {
    title: 'Hello',
    content: 'Are you sure to continue?',
    contentLoaded: function(){
    },
    icon: '',
    confirmButton: 'Okay',
    cancelButton: 'Close',
    confirmButtonClass: 'btn-default',
    cancelButtonClass: 'btn-default',
    theme: 'white',
    animation: 'zoom',
    closeAnimation: 'scale',
    animationSpeed: 500,
    animationBounce: 1.2,
    keyboardEnabled: false,
    rtl: false,
    confirmKeys: [13], // ENTER key
    cancelKeys: [27], // ESC key
    container: 'body',
    confirm: function () {
    },
    cancel: function () {
    },
    backgroundDismiss: false,
    autoClose: false,
    closeIcon: null,
    columnClass: 'col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1',
    onOpen: function(){
    },
    onClose: function(){
    },
    onAction: function(){
    }
}; 

 

配置参数

jquery-confirm插件的可用配置参数有:

参数类型默认值描述
titleString'Hello'对话框的标题
contentString, Function'Are you sure to continue?'对话框的内容,也可以通过一个函数返回ajax内容
contentLoadedfunctionfunction(){}如果通过url前缀来调用内容,如url:http://abc.com/xyz,该参数将是回调函数
iconString''标题前面的图标
confirmButtonString'Okay'确认按钮的文本
cancelButtonString'Close'取消按钮的文本
confirmButtonClassString'btn-default'确认按钮的的class
cancelButtonClassString'btn-default'取消按钮的class
themeString'white'对话框的颜色主题,可选值有:'white', 'black', 'material' , 'bootstrap'
animationString'zoom'打开对话框时的动画效果。可选值有: right, left, bottom, top, rotate, none, opacity, scale, zoom, scaleY, scaleX, rotateY, rotateYR (reverse), rotateX, rotateXR (reverse)
closeAnimationString'scale'关闭对话框时的动画,和animation参数的可选值相同
animationSpeedNumber500动画的持续时间,单位毫秒
animationBounceFloat1.2打开对话框时添加弹性效果,1=没有弹性效果
keyboardEnabledBooleanfalse使用回车键来确认,使用Esc键来取消
confirmKeysArray[13]当使用keyboardEnabled参数时,可以设置一组键来触发确认事件,默认为13
cancelKeysArray[27]当使用keyboardEnabled参数时,可以设置一组键来触发取消事件,默认为27
rtlBooleanfalse使用从右到左的布局
containerString'body'指定生成的对话框代码被添加到哪里
confirmFunctionfunction(){}用户点击了确认按钮之后的回调函数
cancelFunctionfunction(){}用户点击了取消按钮之后的回调函数
backgroundDismissBooleanfalse是否允许点击对话框之外的区域来关闭对话框
autoCloseStringfalse在指定的时间之后如果用户没有响应则自动关闭对话框。取值:'confirm|400'
closeIconBooleannull在对话框没有按钮的情况下,关闭按钮是可见的。将该参数设置为true可看见关闭按钮
closeIconClassStringfalse默认使用'X'作为关闭按钮,你可以通过该参数来修改
columnClassString'col-md-4 col-md-offset-4
col-sm-6 col-sm-offset-3
col-xs-10 col-xs-offset-1'
使用Bootstrap网格系统来进行布局
onOpenFunctionfunction(){}当对话框元素被渲染之后触发
onCloseFunctionfunction(){}当对话框被关闭时触发
onActionFunctionfunction(){}当任何指令被执行后都会触发该回调函数
watchIntervalNumber100Watch the modal for changes and gets centered on the screen

API

通过var jc = $.confirm()会返回一个对象实例的引用。通过jc引用可以打开对话框。

var jc = $.confirm({title: 'awesome'}); // jc will be used in the examples below  

        jc.close():关闭对话框。
        var jc = $.confirm({
            ...
        })
        jc.close(); // destroy. 

        jc.isClosed():返回对话框是否被关闭的布尔值。
        jc.setTitle(string):设置标题。
        jc.setContent(string):设置内容。
        jc.setIcon(iconClass):设置按钮。
        jc.setDialogCenter():将对话框居中显示。
        jc.$body:别名:jc.$b,模态窗口对象。
        jc.$content:别名:jc.contentDiv。可以通过该对象来访问对话框的内容。
        var jc = $.confirm({
            content: 'Yeah, this is awesome'
        })
        console.log(jc.$content.html()); // Yeah, this is awesom
        jc.$title:可访问标题的对象。
        jc.$icon:可访问图标的对象。
        jc.$confirmButton:可访问确认按钮的对象。
        jc.$cancelButton:可访问取消按钮的对象。
        jc.$closeButton:可访问关闭按钮的对象。
        jc.$target:可访问点击元素的对象。

 

转载于:https://www.cnblogs.com/4job/p/10669922.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值