Jquery 对话框 - “动态渲染”按钮

发布于 2024-12-21 16:01:43 字数 152 浏览 2 评论 0原文

有没有办法控制在 Jquery 对话框中显示哪些按钮?

场景:

也许存在程序逻辑,在保存数据后,对话框能够显示“删除”按钮。 (意思是在对话框内提交表单后,整个对话框都会刷新?>>这包括正在加载的对话框上的按钮?)

有什么建议吗?

Is there a way to control which buttons to display in a Jquery Dialog?

Scenario:

Perhaps there might be program logic whereby after saving the data, the dialog is then able to show a "Delete" button. (meaning after a form submit within the dialog, the entire dialog refreshes? >> this includes the buttons on the dialog being loaded?)

Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心的位置 2024-12-28 16:01:43

您可以使用 jQuery 对话框上按钮选项的 getter 和 setter 方法来执行此操作。以下示例取自 jQuery UI 文档

//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 );

这是一个工作示例

You can do this using the getter and setter methods on the buttons options on the jQuery dialog. The following example is taken from the jQuery UI docs:

//getter
var buttons = $( ".selector" ).dialog( "option", "buttons" );

//setter
$( ".selector" ).dialog( "option", "buttons", [
    {
        text: "Ok",
        click: function() { $(this).dialog("close"); }
    }
] );

So in your example you could do:

Adding

// 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 );

Removing

// 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 );

Here's a working example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文