[英]Return value from jquery model confirm or model dialog box
我有一個像這樣的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的新手。
你無法完全按照自己的意願擁有它。 您可以使用其他方式執行此操作:
看看我的小提琴
基本上我有一個全局變量feedback
var feedback = false;
在ok
或cancel
對話框時,我設置了適當的值。 IMO為您的代碼增加了一些靈活性
我建議你使用callback
。
buttons: {
Ok: function() {
callbackSuccess();
$( this ).dialog( "close" );
},
Cancel: function() {
callbackCancel();
$( this ).dialog( "close" );
}
}
callbackSuccess
和callbackCancel
- 是一個簡單的函數
如果為ConfirmDialog創建幫助程序,則更容易傳遞回調
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.