打开jQuery-ui对话框时如何隐藏对话框按钮 [英] How to hide dialog buttons when a jQuery-ui dialog is opened

查看:105
本文介绍了打开jQuery-ui对话框时如何隐藏对话框按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开jQuery-UI对话框时,如何隐藏按钮(例如,隐藏保存"按钮)?

When opening a jQuery-UI dialog, how can I hide a button (for instance, hide the "Save" button)?

http://jsfiddle.net/ba6jwh54/1/

<!-- head --> 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/ui-lightness/jquery-ui.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js" type="text/javascript"></script>

<!-- body -->
<div id="dialog" class="dialog" title="My Title"></div>
<a href="#" id="open">open</a>

// javascript
$(document).ready(function() {
    $('#open').click(function() {
        $("#dialog").dialog("open");
    });
    $("#dialog").dialog({
        autoOpen: false,
        height: 400,
        width: 350,
        modal: true,
        open: function() {
            var dialog = $(this);
            console.log('dialog', dialog);
            var buttons = dialog.dialog("option", "buttons");
            console.log('buttons', buttons);
            //Change names this way...
            buttons[0].text = 'Save2';
            buttons[1].text = 'Cancel2';
            dialog.dialog("option", "buttons", buttons);
            //How do I hide a button (i.e. hide Save button)?
        },
        buttons: [{
            text: 'SAVE',
            click: function() {
                alert('save');
                $(this).dialog("close");
            }
        }, {
            text: 'CANCEL',
            click: function() {
                $(this).dialog("close");
            }
        }]
    });
});

推荐答案

最简单*的方法是保留当前对话的

The easiest* way is to get a hold of the current dialog's widget element and .find() the button inside it:

open: function () {
    var $widget = $(this).dialog("widget");
    $widget.find(".ui-dialog-buttonpane button:first").hide();
}

更新的小提琴

比在页面上找到所有button元素并猜测哪个元素更容易.

Easier than finding all the button elements on the page and guessing which one is which.

这篇关于打开jQuery-ui对话框时如何隐藏对话框按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆