swal如何加入html语言,Sweet Alert弹窗点击确定后执行页面跳转等操作

可不可以点击 Sweet Alert 弹窗的确定按钮后跳转页面呢?答案是可以的:

首先参考上文,引入 Sweet Alert 所需的文件,我这里写了一个修改密码的确认框。

1e2897fb7aae09da33ee794ecb732af7.png

点及修改后,会弹出修改成功提示,再点击重新登陆按钮,跳转登录页面。

b1545cdb33ee19b7b99e758c0cfeb110.png

添加一个页面跳转的代码就可以了。.then(function () {

window.location.href = "/login.html"

})

代码如下:swal({

title: "您确定要修改密码吗",

text: "修改后,请使用新密码登陆!",

type: "warning",

showCancelButton: true,

confirmButtonColor: "#DD6B55",

confirmButtonText: "修改",

cancelButtonText: "取消",

closeOnConfirm: false

}).then(function () {

swal({

title:"修改成功!",

text: "请使用新密码登陆。",

type: "success",

confirmButtonText: "重新登陆",

}).then(function () {

window.location.href = "/login.html"

})

})

下面的代码也可以用,不过规范的话还是用上面的:swal({

title: "您确定要修改密码吗",

text: "修改后,请使用新密码登陆!",

type: "warning",

showCancelButton: true,

confirmButtonColor: "#DD6B55",

confirmButtonText: "修改",

cancelButtonText: "取消",

closeOnConfirm: false

}, function () {

swal({

title:"修改成功!",

text: "请使用新密码登陆。",

type: "success",

confirmButtonText: "重新登陆",

}, function () {

window.location.href = "/login.html"

})

})

.then字面意思就是上一步执行完了,执行下一步,不过这是 Promise 对象的方法,非 Promise 对象没有 then 方法。在 jQuery 中 Promise 叫作 Deferred 对象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值