SimpleModal 确认覆盖:希望回调返回 true 或 false,而不是 URL 重定向
你好,我是一个 jquery 新手,正在尝试使用 simplemodal 插件。在此尝试之前,我的代码是
isYes = confirm("Are you sure . . . "?);
return isYes;
Simplemodal demo 进行 URL 重定向。我想像默认确认按钮那样返回 true 或 false。
这可能吗?
当我尝试此操作时(请参阅下面的代码),会弹出模式对话框,但它不会等待,而是在我可以单击任何内容之前继续执行底层按钮操作!
这就是我调用确认的方式:
confirm(confirm_message, function(isYes) { return isYes; });
function confirm(message, callback) {
var isYes = false;
$('#confirm').modal({
closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
position: ["20%", ],
overlayId: 'confirm-overlay',
containerId: 'confirm-container',
onShow: function(dialog) {
var modal = this;
$('.message', dialog.data[0]).append(message);
// if the user clicks "yes"
$('.yes', dialog.data[0]).click(function() {
isYes = true;
// call the callback
if ($.isFunction(callback)) {
callback.apply(this, jQuery.makeArray(isYes));
}
// close the dialog
modal.close(); // or $.modal.close();
});
}
});
return isYes;
}
Hi I am a jquery newbie and trying to use the simplemodal plugin. Before this attempt my code was
isYes = confirm("Are you sure . . . "?);
return isYes;
The simplemodal demo does a URL redirect. I would like to return true or false the way a default confirm button does.
Is this possible?
When I try this (Please see code below), the modal dialog pops up, but instead of waiting, it proceeds with the underlying button action before I can click anything!
This is how I call confirm:
confirm(confirm_message, function(isYes) { return isYes; });
function confirm(message, callback) {
var isYes = false;
$('#confirm').modal({
closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
position: ["20%", ],
overlayId: 'confirm-overlay',
containerId: 'confirm-container',
onShow: function(dialog) {
var modal = this;
$('.message', dialog.data[0]).append(message);
// if the user clicks "yes"
$('.yes', dialog.data[0]).click(function() {
isYes = true;
// call the callback
if ($.isFunction(callback)) {
callback.apply(this, jQuery.makeArray(isYes));
}
// close the dialog
modal.close(); // or $.modal.close();
});
}
});
return isYes;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现此操作的步骤:
1)从“否”按钮中删除 simplemodal-close
2)在confirm.js中,将:更改
为:
3)也在confirm.js中,将:更改
为:
希望有所帮助。
-埃里克
Steps to make this work:
1) Remove simplemodal-close from the No button
2) In confirm.js, change:
To:
3) Also in confirm.js, change:
To:
Hope that helps.
-Eric
我做了一个简单的脚本来修改 JavaScript 默认确认。希望这对你有用:)
这里有一个简单的脚本来调用确认...
回调函数:
您还可以修改默认警报或提示。最后是...你需要构建 css 来确认:)
I Made a simple script to modify JavaScript default confirm. hope this is work for u :)
And here a simple script to calling that confirm...
Function for callback :
You also can modified that for default alert or prompt. the last is... u need to build css for that confirm :)