[英]Adding addition buttons to jquery dialog box
我有一個jquery對話框,希望在滿足條件時動態添加一個附加按鈕。
我將對話框設置為頁面加載,如下所示
$("#confirmT").dialog({
autoOpen: false,
open: function() {
pullResources(cat, id);
},
autoResize:true,
width: 800,
modal: true,
title: 'Select Resources',
buttons: {
Cancel: function() {$(this).dialog( "close" );}},
close: function() {
}
});
然后,當條件為真時,我希望它添加另一個按鈕,以允許用戶向數據庫中添加某些內容。 這就是我到目前為止(從jQuery ui網站獲得的一切,但是什么也沒有發生。不會產生錯誤,什么也不會產生。
if ($sub == 1)
{
?>
<script type = 'javascript'>
function addbuttons()
{
// Setter
$( "#confirmT" ).dialog( "option", "buttons",
[
{
text: "Ok",
click: function() {
//do something
}
}
]
);
}
addbuttons();</script>
<?php
}
任何幫助將不勝感激。
謝謝
最初添加按鈕,並根據情況僅調用javascript函數來隱藏按鈕。
JS:-
$(function () {
$("#dialog-confirm").dialog({
resizable: false,
height: 200,
width: 500,
modal: true,
buttons: [{
text: "Delete all items",
class: "aditya",
click: function () {
$(this).dialog("close");
}
}, {
text: "Cancel",
click: function () {
$(this).dialog("close");
}
}]
});
function foo() {
$("#dialog-confirm").closest(".ui-dialog").find(".aditya").hide();
}
foo();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.