Ayh*_*han 9 jquery confirm modal-dialog twitter-bootstrap
我正在尝试使用twitter bootstrap模式而不是自定义确认对话框.
我的功能
function getConfirm(confirmMessage){
if ( confirmMessage == undefined){
confirmMessage = '';
}
$('#confirmbox').modal({
show:true,
backdrop:false,
keyboard: false,
});
$('#confirmMessage').html(confirmMessage);
$('#confirmFalse').click(function(){
$('#confirmbox').modal('hide');
return false;
});
$('#confirmTrue').click(function(){
$('#confirmbox').modal('hide');
return true;
});
}
</script>
<div class="modal" id="confirmbox" style="display: none">
<div class="modal-body">
<p id="confirmMessage">Any confirmation message?</p>
</div>
<div class="modal-footer">
<button class="btn" id="confirmFalse">Cancel</button>
<button class="btn btn-primary" id="confirmTrue">OK</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
调用该函数
var confimChange=getConfirm("Do You confirm?");
if(confimChange){
alert('perfect you confirmed')
}else{
alert('why didnt you confirmed??')
}
Run Code Online (Sandbox Code Playgroud)
问题是getConfirm函数没有返回true或false.
工作代码:
if(receiverListCount > 0){
var confimChange=confirm("Message");
if(confimChange){
resetReceiverList();
}else{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
修改和更改/不工作后的代码片段
if(activeDiv == '#upload'){
if(listOfSelectedGroups.length> 0|| receiverListCount > 0){
getConfirm("message",function(result){
if(result){
resetReceiverList();
}else{
return false;
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
最后我决定使用bootboxjs
Llo*_*oyd 22
你的方法是错误的,它会异步执行一些,这样它就不会等到模态对话框在返回之前被关闭.尝试这样的事情:
function getConfirm(confirmMessage,callback){
confirmMessage = confirmMessage || '';
$('#confirmbox').modal({show:true,
backdrop:false,
keyboard: false,
});
$('#confirmMessage').html(confirmMessage);
$('#confirmFalse').click(function(){
$('#confirmbox').modal('hide');
if (callback) callback(false);
});
$('#confirmTrue').click(function(){
$('#confirmbox').modal('hide');
if (callback) callback(true);
});
}
getConfirm('Are you sure?',function(result) {
// Do something with result...
});
Run Code Online (Sandbox Code Playgroud)
但请注意,您只需要初始化模态一次并挂钩事件一次.我会给出模态体和ID,然后在显示之前简单地更改内容.
您还应将背景设置为true,您需要确认以阻止用户在确认之前访问该页面.
| 归档时间: |
|
| 查看次数: |
20189 次 |
| 最近记录: |