对于以下代码,我想将其设置为同步模式。这意味着单击“确定”按钮后将显示alert(true)。请注意,我不需要回调函数。并使其同步。
var isValidated = false;
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"OK": function() {
isValidated = true;
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
if(isValidated){
alert("true");
}
else{
alert("false");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<div id="dialog-confirm">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span></p>
</div>