繁体   English   中英

关闭按钮单击事件的模式对话框

[英]closing a modal dialog on button click event

我有一个模态窗口,在下拉列表中点击一个项目时打开。 按下按钮,我无法实现关闭对话框。

 var $that = this;
 $("#btncart_cancel").on("click", function () {
      ///// ***********close the dialog *************** 
      /// tried this but not working
      $that.dialog("close");
 });

我的代码:

$(".ddlCart li").click(function (e) {
$('#actionsCart').slideToggle();

var ddlselectedVal = $(this).attr('id');
var selectedListinsCount = selected_Listings.length;
var SelectedMlsnums = selected_Listings.join();
var agentId = $("#AgentId").val();

var EnvironmentURL = $("#EnvironmentURL").val();

var autoUrl = "/Stats/SearchContacts";
var Action = "PreAddToCart"

var postData = {
    AgentId: agentId,
    Mlsnums: SelectedMlsnums,
    ActionTypeValue: Action
};
var $that = this;
var close = function (event, ui) {
    $(this).dialog("destroy");
}
var open = function (event, ui) {
    var agentId = $("#AgentId").val();
    var url = EnvironmentURL + "/Stats/SearchContacts";

    $("#btncart_cancel").on("click", function () {
        ///// ***********close the dialog *************** 
    });

    $("#btncart_submit").on("click", function () {
        $(".liloading").show();

        if (App.ContactInfo.Id != 'undefined') {
            var contactKey = App.ContactInfo.Id;
            var cartName = App.ContactInfo.Name;
        } else {
            var contactKey = 0;
            var cartName = 'My Personal Cart';
        }

        var note = $("#txtNotes").val();
        var url = EnvironmentURL + "/Stats/Cart";

        //Send the data using post and put the results in a div                   
        $.post(url, {
            CartName: cartName,
            Notes: note,
            Contactkey: contactKey,
            ActionTypeValue: "AddToCart"
        },

        function (data) {
            // Replace current data with data from the ajax call to the div.         
            $("#dvModalDialog").empty().append(data);

        });
    });
};

var rd = Mod.ReportsDialog({
    title: 'Add To Cart',
    close: close,
    open: open
});
rd.url = EnvironmentURL + "/Stats/Cart";
rd.targetElement = '#dvModalDialog' // '#dvSendEmail'
rd.formName = '#frmCart'
rd.postData = postData
rd.open();
var $that = this;
});

我用close方法看到的问题是$that不是JQuery对象。

您可以使用$($that).dialog("close")$(this).dialog("close")$('#dvModalDialog').dialog("close")修复此问题。

   $(document).ready(function () {
     $('#modalClose').click(function (){
                window.setTimeout(function () {
                  $('#contact').modal('hide');
                }, 5000);
              });
          });

对于Button使用id = modalClose和对于模态使用id = contact

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM