Sweetalert阻塞像正常提示
sweetalert blocking like normal prompt
我使用swal (http://t4t5.github.io/sweetalert)从用户点击某些东西时获取一些数据。然后我想从我调用的函数中返回它。换句话说,对于下面的示例,我希望将labels
中条目的文本设置为输入值。问题是它似乎在关闭/输入数据之前返回:
.on('dblclick', function(l) {
labels.text(function (e) {
return swal({
title: "Edit label"
},
function(inputValue){
if(inputValue) {
return inputValue
}
});
})
});
正常的prompt alert
阻塞所以可以这样做,swal
可以这样做吗?
谢谢
虽然不能使用Sweet Alerts块,但可以使用它的回调功能来触发任何需要先解除警报的代码。例子中有几个这样的例子。例如,假设您有一个是/否样式警告,下面是文件删除示例。
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){
//The callback will only fire on cancel if the callback function accepts an
//argument. So, if the first line were 'function () {' with no argument, clicking
//cancel would not fire the callback.
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
或者AJAX示例:
swal({
title: "Ajax request example",
text: "Submit to run ajax request",
type: "info",
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true,
},
function(){
setTimeout(function(){
swal("Ajax request finished!");
}, 2000);
});
在这两种情况下,直到与警报交互后才触发回调,并且调用的结果作为参数传递给回调。
假设你需要等待,直到有人点击ok。
swal({
title: "Delete your account?",
text: "Clicking on continue will permanently delete your account.",
type: "warning",
confirmButtonText: "Continue",
closeOnConfirm: false
}, function () {
swal("Deleted account", "We'll miss you!", "success");
});
注意: closeOnConfirm
/closeOnCancel
只有在回调中显示后续警报时才需要false
。如果设置为true
,它将在显示给用户之前关闭第二个警报。然而,如果你正在做一些与swal
无关的事情,并且你没有关闭它,它将无限期地保持打开状态。
swal({
title: "Delete your account?",
text: "Clicking on continue will permanently delete your account.",
type: "warning",
confirmButtonText: "Continue"
}, function () {
console.log("This still shows!")
});
如果你想在做一些与swal
无关的事情时保持警报打开,你应该在代码末尾调用swal.close()
。
swal({
title: "Delete your account?",
text: "Clicking on continue will permanently delete your account.",
type: "warning",
confirmButtonText: "Continue",
closeOnConfirm: false
}, function () {
console.log("This still shows!");
setTimeout(function () {
// This will close the alert 500ms after the callback fires.
swal.close();
}, 500);
});
不,它不能,没有办法创建阻塞代码等待用户输入。唯一的方法是JS已经提供的:提示,警报等。只需从回调中运行所需的代码。
相关文章:
- 提示使用服务器端事件处理程序激活JavaScript
- d3.js Chord图的动态工具提示
- Javascript 可选类型提示
- 单击按钮后启动javascript提示
- Graphiti中是否有任何工具提示功能
- JS,用于播放提示音以通知未按预期工作
- "工具提示"jQuery插件坏了
- 如何在 JavaScript 和 HTML 中更改对输入框的提示响应
- 单元格的工具提示或标题不显示超过2000个字符
- JQM simpledialog:如何提示输入数字
- d3.js用按钮更新条形图工具提示
- 使Intro.js工具提示响应
- 画布中绘制的矩形区域的弹出工具提示
- 使用CSS/JavaScript更改剑道图工具提示文本颜色
- 是否可以用变量确认提示警报
- 禁用NVD3 multiBarHorizontalChart中0值的工具提示
- 模态提示-如何重写此代码
- 更改提示工具提示的重力/位置
- JQuery UI工具提示-工具提示的位置错误(在页面左侧,而不是按钮周围)
- Angularjs工具提示:工具提示HTML模板没有更新