bootstrap气泡确认

基于bootstrap的popover插件实现,效果如下:

插件代码:


(function ($) {
    $.fn.extend({
        popConfirm: function (options,fun) {
            var _this = $(this);
            var defaults = {
                title: "提示",
                content: "确认此操作?",
                placement: "auto",
                container: "body",
                yesBtn: "确认",
                noBtn: "取消"
            }
            options = $.extend(defaults, options);
            _this.popover({
                trigger: "manual",
                title: options.title,
                html: true,
                //template: '', //你自定义的模板
                placement: options.placement,
                container: options.container,
                content: function () {
                    let _btnGroup = $("<p>", {
                        class: "button-group",
                        style: "margin-top: 10px; text-align: center;",

                    });

                    let _btnNo = $("<button>", {
                        type: "button",
                        text: "取消",
                        style: "padding:0 6px;",
                        class: "btn btn-small",
                        click: function () {
                            _this.popover('destroy');
                        }
                    });

                    let _btnOk = $("<button>", {
                        type: "button",
                        text: "确认",
                        style: "padding:0 6px;margin-left:6px",
                        class: "btn btn-small btn-danger",
                        click: function () {
                            if (fun) {
                                fun();
                            }
                            _this.popover('destroy');
                        }
                    });
                    _btnNo.appendTo(_btnGroup);
                    _btnGroup.append(_btnOk);
                    return $("<div>").html(options.content).append(_btnGroup);
                }
            });
            _this.popover('toggle');

        }
    })
}(jQuery));

用法:


<button id="btn" type="button"  >
    基于Popover实现气泡确认
</button>


$("#btn").click(function(){
 
   $(this).popConfirm({ content: "删除后将无法恢复!!!!" }, function () {
        alert("ok");
   });

});

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值