Jquery对话框在一定时间后显示关闭按钮

时间:2012-04-10 15:31:51

标签: jquery

如何在经过一段时间后显示关闭按钮,我尝试了settimeout但它不会工作。有人可以提供基本样本,以便在一定时间后显示关闭按钮。

感谢

修改
这是我如何做自定义按钮,因为有人问我这个

 var myButtons = {
                'Close': function () {
             },
             'Do not show this again': function () {
                    $.ajax({
                        type: "POST",
                        url: pagename,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            if (response.d == true) {
                            }
                        }
                    });
                }
             };

$("#div").html("").dialog({ modal: true, resizable: false, width: 830, height: 580, show: 'slow', title: '', open: function (event, ui) { $(".ui-dialog-titlebar", $("#div").parent()).hide(); }, buttons: myButtons });

这就是我如何做自定义按钮。我有mybuttons变量的原因是因为我使用条件语句并基于我在对话框打开时显示不同的按钮。

2 个答案:

答案 0 :(得分:1)

尝试以下内容,

DEMO

var $dialog = $('Your Dialog Div'); // Your Dialog Div

//Get Dialogs Parent and find the close button. 
//jQuery assigns .ui-dialog-titlebar-close class to the close X (a tag)
var $dialogCloseBtn = $dialog.parent().find('.ui-dialog-titlebar-close'); 

//hide the close button
$dialogCloseBtn.hide();

//show the close button after 10 seconds
setTimeout(function () {
    $dialogCloseBtn.fadeIn(100);
}, 10000);

假设:以上代码假设您要隐藏/显示您在对话框标题中看到的jQuery默认关闭按钮。

答案 1 :(得分:0)

如果对话框中有一个带有id=close_dialog_button的关闭按钮,请为其指定display:none样式,然后使用此代码:

$( "#dialog_div" ).dialog({
   open: function(event, ui) {
    setInterval(function() {
        $("#close_dialog_button").show();
    }, 10000);
 }
});