使用fancybox扩展Javascript确认框
我用fancybox扩展了我所有的使用fancybox扩展Javascript确认框,javascript,fancybox,Javascript,Fancybox,我用fancybox扩展了我所有的警报,如下所示 window.alert = function(message){ $("#alert_message_box .warmsg span").html(message); $.fancybox({'href':'#alert_message_box'}); return false; } 它工作得很好。我还尝试扩展confirmbox-like window.confirm = function(message){
警报
,如下所示
window.alert = function(message){
$("#alert_message_box .warmsg span").html(message);
$.fancybox({'href':'#alert_message_box'});
return false;
}
它工作得很好。我还尝试扩展confirm
box-like
window.confirm = function(message){
$("#confirm_message_box .warmsg span").html(message);
$.fancybox({'href':'#confirm_message_box'});
}
确认消息\u框
div包含两个按钮,Yes
和No
if(确认(警报消息)){
}
在这种情况下,如何调用confirm
函数,以及如何将true
和false
返回到被调用函数
我不知道覆盖这些函数是否有任何问题
这是一个带有jquery的JSFIDLE演示(这里不使用fancybox)
在这种情况下,您必须更改您的工作流程,因为Fancybox版本的确认对话框不是模态对话框(它不会暂停脚本执行)。您必须使用回调来在相应的按钮单击时调用:
window.confirm = function(message, onYes, onNo) {
$("#confirm_message_box .warmsg span").html(message);
$.fancybox({
href: '#confirm_message_box'
afterLoad: function() {
this.inner.find('.btn-yes').click(onYes);
this.inner.find('.btn-no').click(onNo);
}
});
}
在fancybox初始化中,您需要将onYes
函数绑定到Yes按钮,将onNo
绑定到No
用法如下:
confirm('Are you sure?', function() {
// he is sure
}, function() {
// cancel something
});
我并不反对,但我发现Yes,No回调方法限制太多,而我自己也发现了一种更灵活的方法
用法示例:
- 经典的是,不是-
- 不太一般的例子
confirm("Do you wish to continue?",
{
/*
Define your buttons here, can handle multiple buttons
with custom title and values
*/
buttons: [
{ class: "yes", type: "button", title: "Yes", value: "yes" },
{ class: "no", type: "button", title: "No", value: "no" },
{ class: "maybe", type: "button", title: "Maybe?", value: "maybe" }
],
modal: true
},
function(resp) {
alert("You clicked " + resp);
}
);