如何在ASP中使用甜蜜警报 [英] How to use sweet alert in ASP

查看:64
本文介绍了如何在ASP中使用甜蜜警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用

SweetAlert2

,点击按钮后,警报已经显示并突然关闭。



我尝试过:



in my project, after clicked the button the alert has been displayed and closed suddenly.

What I have tried:

$(document).ready(function () {
    $("#Button1").click(function () {
       swal({
          title: 'Are you sure?',
          text: "You won't be able to revert this!",
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Yes, delete it!',
          cancelButtonText: 'No, cancel!',
          confirmButtonClass: 'btn btn-success',
          cancelButtonClass: 'btn btn-danger',
          buttonsStyling: false
        }).then(function () {
          swal(
            'Deleted!',
            'Your file has been deleted.',
            'success'
          )
        }, function (dismiss) {
          // dismiss can be 'cancel', 'overlay',
          // 'close', and 'timer'
          if (dismiss === 'cancel') {
            swal(
              'Cancelled',
              'Your imaginary file is safe :)',
              'error'
            )
          }
        });
    });
});







<asp:Button ID="Button1" runat="server" Text="Button" />

推荐答案

(文件).ready(function(){
(document).ready(function () {


(#Button1)。点击(function(){
swal({
title:'你确定吗?',
text:你将无法恢复这个!,
类型:'警告',
showCancelButton:true,
confirmButtonColor:'#3085d6',
cancelButtonColor:'#d33',
confirmButtonText:'是的,删除它!',
cancelButtonText:'不,取消!',
confirmButtonClass:'btn btn-success',
cancelButtonClass:'btn btn-danger',
buttonsStyling:false
})。then(function(){
swal(
'已删除!',
'您的文件已被删除。',
'成功'

},函数(解散){
//解雇可以'取消','叠加',
//'关闭','计时器'
if(dismiss === '取消'){
swal(
'已取消',
'您想象中的文件是安全的:)',
'错误'

}
});
});
});
("#Button1").click(function () { swal({ title: 'Are you sure?', text: "You won't be able to revert this!", type: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', confirmButtonClass: 'btn btn-success', cancelButtonClass: 'btn btn-danger', buttonsStyling: false }).then(function () { swal( 'Deleted!', 'Your file has been deleted.', 'success' ) }, function (dismiss) { // dismiss can be 'cancel', 'overlay', // 'close', and 'timer' if (dismiss === 'cancel') { swal( 'Cancelled', 'Your imaginary file is safe :)', 'error' ) } }); }); });







<asp:Button ID="Button1" runat="server" Text="Button" />


您需要停止按钮的点击事件继续,否则它将继续提交您的表单,这将导致页面刷新您正在看。

You need to stop the button's click event from continuing otherwise it will go on to submit your form which will cause the page refresh you are seeing.


这篇关于如何在ASP中使用甜蜜警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆