我有一个像这样的 javascript 函数:
Javascript:
function dailog_box(){
$( "#dialog-confirm" ).dialog({
resizable: false,
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
return true; //i want to return value here
},
Cancel: function() {
$( this ).dialog( "close" );
return false; //i want to return value here
}
}
});
}
HTML
<div id="dialog-confirm" title="Prescriptions" style="display:none;">
<p>
<span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
These items will be permanently deleted and cannot be recovered. Are you sure?<br/>
<input type="checkbox" name="check_od" id="check_od"/> The prescription is correct;
</p>
</div>
调用 dialog_box()
函数后,我希望在变量标志中返回值,我这样做了:
Javascript
var flag = dailog_box();
alert(flag);
但结果未定义。并且在我单击任何按钮之前也会发生警报。那么在模型按钮中单击任何按钮后我应该怎么做才能获得值
有关更多信息,您可以查看 http://jsfiddle.net/8e388/13/ 我想要提醒返回值。 顺便说一句,我是 jsfiddle 的新手。
最佳答案
你不能随心所欲地拥有它。您可以使用另一种方式执行此操作:
查看我的 fiddle
基本上我有一个全局变量feedback
var feedback = false;
在对话框的ok
或cancel
上,我设置了适当的值。 IMO 这为您的代码增加了更多的灵 active
关于javascript - 从 jquery 模态确认或模态对话框返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16957212/