How to return boolean from confirm dialog plugin?
In JavaScript, they have confirm dialog which returns true or false, upon clicking yes or no button.
if (confirm('Your question')) {
// do things if OK
}
But it is not customizable and can be stopped upon clicking the check box in the popup.
So I want to use JQuery confirmation or dialogue plugin. However plugin I found, does not returns true or false. It comes with button functions and I can't return true or false from the button functions.
Is there any way to return variable like Boolean in jQuery confirm ?
$('.dialog button').click(function () {
if($(this).attr('class') == 'true') {
$('p').text('Ok was clicked');
} else {
$('p').text('Cancel was clicked');
}
});
.dialog {
background-color: #cecece;
border: 1px solid #000;
padding: 1%;
font-family: 'Segoe UI';
text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dialog">
<button class="true">Ok</button>
<button class="false">Cancel</button>
</div>
<p></p>
It can't return the value, but there is a workaround:
var returnValue;
$("#confirmdialog").dialog({
modal: true,
buttons: [{
text: "Yes",
"id": "btnOk",
click: function () {
returnValue = true;
},
},
{
text: "No",
click: function () {
returnValue = false;
},
}],
});
And then check the returnValue
if(returnValue){
}
there is no jquery plugins which allow inline custom confirmation dialogs (return false/true). Each of them work on handling callbacks. And there isn't only jquery ui dialog there are plenty of them. Here is a list of them.
链接地址: http://www.djcxy.com/p/71706.html上一篇: 默认操作不会在新通话中重置
下一篇: 如何从确认对话框插件返回布尔值?