有没有办法控制在Jquery对话框中显示哪些按钮?
情景:
也许可能存在程序逻辑,在保存数据之后,对话框能够显示"删除"按钮。 (意味着在对话框中提交表单后,整个对话框会刷新?>>这包括正在加载的对话框上的按钮?)
有什么建议吗?
答案 0 :(得分:2)
您可以使用jQuery对话框上按钮选项上的getter和setter方法执行此操作。以下示例取自jQuery UI docs:
//getter
var buttons = $( ".selector" ).dialog( "option", "buttons" );
//setter
$( ".selector" ).dialog( "option", "buttons", [
{
text: "Ok",
click: function() { $(this).dialog("close"); }
}
] );
所以在你的例子中你可以做到:
<强>添加强>
// Get existing buttons
var buttons = $( ".selector" ).dialog( "option", "buttons" );
// Add a delete button
buttons.push({
text: "Delete",
click: function () {
// Do your deletion stuff
}
});
// Put the modified button Array back in
$( ".selector" ).dialog( "option", "buttons", buttons );
<强>卸下强>
// Get existing buttons
var buttons = $( "#testDialog" ).dialog( "option", "buttons" );
$.each(buttons, function (i) {
if (this.text === "Delete") {
// We've found the button we want to delete so remove it from Array
buttons.splice(i, 1);
// No point in continuing the loop as we've removed what
// we want to remove.
return;
}
});
// Put the modified button Array back in
$( "#testDialog" ).dialog( "option", "buttons", buttons );