如何在单击按钮时关闭简单的模式对话框

How to close a simple modal dialog on a button click?

本文关键字:简单 模式 对话框 单击 按钮      更新时间:2023-09-26

在这里,我尝试在单击按钮时关闭模态对话框,但它没有关闭对话框。这是我的代码

function closemodal() {
    alert("true");
    $.modal.close();
    return false;
}

protected void btnOK_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ScriptRegistration", "closemodal();", true);
}
我需要

调用一个JavaScript函数,然后我需要关闭该对话框。任何建议??

编辑:

  $(document).ready(function () {
        $('#MainContent_uscRetailParameters_btnOK').click(function (e) {
            closemodal();
            return false;
        });
        function closemodal() {
            $.modal.close();
        }
    });

编辑2:

  $('#CusCatPOPUP .basic').click(function (e) 
{ 
$('#CusCatPOPUP-content').modal(); 
return false; 
}
); 

除非我错过了重点:

$('#MainContent_uscRetailParameters_btnOK').click(function (e) {
    MyFunctionCall();   //i.e. call you function here
    $.modal.close();
    return false;
});

可能是其他地方的错误,请检查您的浏览器控制台。

创建了一个示例:http://jsfiddle.net/eTnJF/

使用代码:

$(document).ready(function() {
    $('.open').click( function() {
        $('#modal').modal();
    });
    $('.close').click( function() {
        closemodal();
        return false;
    });
    function closemodal() {
        alert("true");
        $.modal.close();
    }
});

哪个工作正常:)

如果你想简单地关闭modalpopup,那么javascript代码就是。

var mpu = $find('ModalPopupExtender1');
mpu.hide();

希望对您有所帮助。

谢谢卡姆兰