我在提交表格时触发了这个甜蜜的事情.
$(".swa-confirm").on("submit", function(e) {
e.preventDefault();
swal({
title: $(this).data("swa-title"),
text: $(this).data("swa-text"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#cc3f44",
confirmButtonText: $(this).data("swa-btn-txt"),
closeOnConfirm: false,
html: false
}, function() {
}
);
});
Run Code Online (Sandbox Code Playgroud)
但点击确认我希望它继续提交表格...
想到了不好的想法,比如:
var confirmed = false;
$(".swa-confirm").on("submit", function(e) {
var $this = $(this);
if (!confirmed) {
e.preventDefault();
swal({
title: $(this).data("swa-title"),
text: $(this).data("swa-text"),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#cc3f44",
confirmButtonText: $(this).data("swa-btn-txt"),
closeOnConfirm: true,
html: false
}, function() {
confirmed = true;
$this.submit();
});
}
});
Run Code Online (Sandbox Code Playgroud)
或者将swa移动到按钮点击而不是提交,并使用提交表单.
但我不喜欢这个解决方案,它看起来像frankesteini给我.当然有更好的方法
我有一个带2个按钮的sweetalert,但我想再添一个按钮.例如,截至目前,我有,我不想再添加一个按钮.请帮忙
$("#close_account").on("click", function(e) {
e.preventDefault();
swal({
title: "Are you sure?",
text: "You will not be able to open your account!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, close my account!",
closeOnConfirm: false
},
function(){
window.location.href="<?php echo base_url().'users/close_account' ?>"
});
});
Run Code Online (Sandbox Code Playgroud)
提前致谢:)
目前正在从事个人项目.我希望用户单击一个按钮,将显示SweetAlert提示,以便用户验证其凭据.但是,我在SweetAlert网站上看到的代码只允许一个输入字段.这是我的代码:
swal({
title: "Authenicating for continuation",
text: "Test",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "Write something"
}, function(inputValue) {
if (inputValue === false) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
// swal("Nice!", "You wrote: " + inputValue, "success");
});
Run Code Online (Sandbox Code Playgroud)
那么,有没有办法可以获得两个输入字段?密码的一个输入字段和文本的另一个输入字段.
我正在尝试升级我的javascript confirm()操作以使用Sweet Alert(http://t4t5.github.io/sweetalert/).目前我的代码是这样的:
<a href="/delete.php?id=100" onClick="return confirm('Are you sure ?');" >Delete</a>
Run Code Online (Sandbox Code Playgroud)
这等待用户在导航到删除页面之前确认.我想在Sweet Alert中使用这个示例,要求用户在删除之前进行确认:
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
Run Code Online (Sandbox Code Playgroud)
我尝试的一切都失败了.显示第一个警报时,页面已经完成并删除了该项目并刷新,然后用户甚至点击了警报按钮.如何让页面等待用户输入?
任何帮助将不胜感激.
我有一个sweetalert的问题,我想在按钮点击时显示确认框警报,但它不起作用
这是我的JS代码:
$(document).ready(function(){
$('[data-confirm]').on('click', function(e){
e.preventDefault(); //cancel default action
//Recuperate href value
var href = $(this).attr('href');
var message = $(this).data('confirm');
//pop up
swal({
title: "Are you sure ??",
text: message,
type: "warning",
showCancelButton: true,
cancelButtonText: "Cancel",
confirmButtonText: "confirm",
confirmButtonColor: "#DD6B55"},
function(isConfirm){
if(isConfirm) {
//if user clicks on "confirm",
//redirect user on delete page
window.location.href = href;
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<a data-confirm='Are you sure you want to delete this post ?'
href="deletePost.php?id=<?= $Post->id ?>"><i class="fa fa-trash">
</i> Delete</a>
Run Code Online (Sandbox Code Playgroud)
导入所有必需的文件.
我的Ajax方法看起来像这样
$.post(url,{
ajax_call:"putDonation",
addresse:addresse,
phone:phone,
email:email,
name:name,
amount:amount,
amountinwords:amountinwords
}).done(function(data){
console.log(data);
var arr = [];
try {
var str = "";
//convert to json string
arr = $.parseJSON(data); //convert to javascript array
$.each(arr,function(key,value){
str +="<li>"+value+"</li>";
});
alert(str);
$(".alert-danger").show();
$("#error").html(str);
} catch (e) {
swal("Jay Gayatri !", 'Donation Sucessful', "success")
$("#donation")[0].reset();
}
})
Run Code Online (Sandbox Code Playgroud)
我想展示一个像这样的甜蜜警报警告弹出窗口
swal({
title: "Are you sure ?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!", …Run Code Online (Sandbox Code Playgroud) 我正在使用SweetAlert2,我收到以下错误
未捕获的TypeError:无法读取未定义的属性'then'
当我使用与SweetAlert页面中建议的完全相同的代码时.
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,
closeOnConfirm: false,
closeOnCancel: false
}).then(function(isConfirm) {
if (isConfirm === true) {
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
} else if (isConfirm === false) {
swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
);
} else …Run Code Online (Sandbox Code Playgroud) 我正在使用最新版本的真棒SweetAlert2 jquery插件.
我有一个带2个按钮的简单SweetAlert.1按钮是确认按钮,另一个是取消按钮.我正在使用html选项向警报添加文本输入.当用户按下确认按钮时,执行AJAX呼叫并关闭警报.
现在我想使用取消按钮执行一些其他代码,而不是关闭警报的默认操作.(用户可以使用showCloseButton:true关闭警报).
所以简而言之:如何删除关闭处理程序并将自己的自定义处理程序添加到swal的取消按钮?
我正在使用Sweet-alert我的角度应用程序.
function GetDataFromServer(url) {
SweetAlert.swal(
{
title: "",
text: "Please wait.",
imageUrl: "../../app/app-img/loading_spinner.gif",
showConfirmButton: false
});
return $http.get(url)
.then(success)
.catch(exception);
function success(response) {
//SweetAlert.swal(
// {
// title: "",
// text: "data loaded",
// });
return response.data;
}
function exception(ex) {
return (ex);
}
}
Run Code Online (Sandbox Code Playgroud)
需求#1(我这篇文章的主要目的)
我正在寻找的是当ajax请求完成时,即控件进入then(),Sweet警报应该自动隐藏.
Req#2同样在请求处理时,我不希望在甜蜜警报中有关闭弹出按钮(确定按钮).
根据文档,showConfirmButton: false应该隐藏它,但事实并非如此.
任何帮助/建议高度赞赏.
谢谢.
问题:
我想在甜蜜警报上单击"确定"后将用户重定向到另一个页面,但是在我出于某种原因打开另一个甜蜜警报之前,用户不会被重定向.
您可以在代码上断点,但页面上没有任何反应.
问题的简单例子:http://jsfiddle.net/ADukg/14306/
注意:包括0秒超时"解决问题"
重现:
1)注意箭头后面的文字.. $ scope.name ="original",你可以看到它显示在页面上.
2)单击"单击第一个"按钮.这运行函数$ scope.changeMe(),它将$ scope.name更新为"delayed ......."
3)到现在为止,按钮上方的文本应该已经更改.但是直到你打开另一个甜蜜的警报,文本才真正改变
4)点击"然后在这里"或"点击第一个"按钮,弹出另一个甜蜜警报,DOM将最终改变.
我很确定这与AngularJS有某种关系,必须使用1.4.3.
有任何想法吗?
HTML:
<div ng-controller="MyCtrl">
<div>
<button ng-click="changeMe()">click first</button>
<button ng-click="decoy()">then here</button>
</div>
<div>
<button ng-click="reset()">reset text</button>
<div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
var myApp = angular.module('myApp',[]);
myApp.controller("MyCtrl", function($scope, $timeout) {
$scope.name = 'original';
$scope.copy = angular.copy($scope.name);
$scope.changeMe = function() {
swal("Text should change now")
// runs on hitting "OK"
.then(function() {
// UNCOMMENT THIS and re-run the fiddle to show expected behavior …Run Code Online (Sandbox Code Playgroud) sweetalert ×10
javascript ×8
jquery ×4
sweetalert2 ×3
ajax ×2
angularjs ×2
button ×1
forms ×1
prompt ×1