JQuery Confirm确认框和一个弹出式提示框

需提前引入jquery文件

源码https://github.com/craftpip/jquery-confirm文件夹中的dist文件,需引入

案例:

$.confirm({
        title: '确认',
        content: '确认删除该条数据?',
        type: 'blue',
        icon: 'glyphicon glyphicon-question-sign',
        buttons: {
            ok: {
                text: '确认',
                btnClass: 'btn-primary',
                action: function () {
                    $.ajax({
                        url: url + "/xx/xx",
                        type: "POST",
                        dataType: "json",
                        crossOrigin: true,
                        data: {
                            openid: id,
                            _method: "DELETE"
                        },
                        success: function (data) {
                            console.log(data)
                            if (data.code == 1) {
                                $('.alert').html('操作成功').addClass('alert-success').show().delay(1500).fadeOut();
                            } else {
                                $('.alert').html('操作失败').addClass('alert-danger').show().delay(1500).fadeOut();
                            }
                        }
                    })
                }
            },
            cancel: {
                text: '取消',
                btnClass: 'btn-primary'
            }
        }
    });

案例中的alert需引入以下代码

<div class="alert"></div>
<!--放到合适的位置-->
/**
 * 弹出式提示框,默认1.2秒自动消失
 * @param message 提示信息
 * @param style 提示样式,有alert-success、alert-danger、alert-warning、alert-info
 * @param time 消失时间
 */
var prompt = function (message, style, time)
{
    style = (style === undefined) ? 'alert-success' : style;
    time = (time === undefined) ? 1200 : time;
    $('<div>')
        .appendTo('body')
        .addClass('alert ' + style)
        .html(message)
        .show()
        .delay(time)
        .fadeOut();
};

// 成功提示
var success_prompt = function(message, time)
{
    prompt(message, 'alert-success', time);
};

// 失败提示
var fail_prompt = function(message, time)
{
    prompt(message, 'alert-danger', time);
};

// 提醒
var warning_prompt = function(message, time)
{
    prompt(message, 'alert-warning', time);
};

// 信息提示
var info_prompt = function(message, time)
{
    prompt(message, 'alert-info', time);
};

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
jQuery一个流行的JavaScript库,它简化了JavaScript编程的复杂性,并提供了许多实用的功能和特性。在jQuery中,可以使用弹出来与用户进行交互,其中包括确定和取消按钮。 要创建一个带有确定和取消按钮的弹出,可以使用jQuery的对话(dialog)组件。以下是一个简单的示例代码: ```html <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $(document).ready(function() { $("#dialog-confirm").dialog({ resizable: false, height: "auto", width: 400, modal: true, buttons: { "确定": function() { // 在这里执行确定按钮的逻辑 $(this).dialog("close"); }, "取消": function() { // 在这里执行取消按钮的逻辑 $(this).dialog("close"); } } }); }); </script> </head> <body> <div id="dialog-confirm" title="确认对话"> <p>确定要执行此操作吗?</p> </div> </body> </html> ``` 在上面的代码中,我们首先引入了jQueryjQuery UI的库文件。然后,在`$(document).ready()`函数中,我们创建了一个对话,并设置了对话的一些属性,如大小、模态等。接下来,我们定义了确定和取消按钮,并在按钮的回调函数中执行相应的逻辑。最后,我们在HTML中创建了一个用于显示对话内容的`<div>`元素。 这样,当页面加载完成后,就会显示一个带有确定和取消按钮的弹出。用户可以点击确定或取消按钮来执行相应的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wcc_Learning

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值