【问题标题】:Return value from Jquery confirm dialog box从 Jquery 确认对话框返回值
【发布时间】:2013-04-25 10:44:21
【问题描述】:

我正在尝试使用以下代码打开一个 Jquery 确认框。

var a = $('#confirm')                
            .data("x","defaultValue")
            .dialog('open');

alert(a.data("x"));

在对话框中我尝试更改 x 的值。

    $("#confirm").dialog({
    resizable: false,
    autoOpen: false,
    height: 180,
    width: 400,
    modal: true,
    buttons: {
        "Leave the page": function() {                
            $(this).data("x","this is a test");                
            $(this).dialog("close");
        },
        Cancel: function() {
            $(this).dialog("close");
        }
    }
});

如何获得 x 的修改值。目前警报显示“DefaultValue”。但想得到“这是一个测试”。

有什么想法吗?

PS:我无法在对话框中使用 window.open() 进行重定向。

【问题讨论】:

    标签: jquery modal-dialog


    【解决方案1】:

    终于解决了这个问题。只是想把它贴在这里,如果有人需要的话。

     $("#confirm").dialog({
        resizable: false,
        autoOpen: false,
        height: 180,
        width: 400,
        modal: true,
        buttons: {
            "Leave the page": function () {
                var anchorId = $(this).data("anchorId");
                var formId = $(this).data("formId");
    
                if (typeof anchorId !== "undefined")
                    window.location.assign(anchorId);
                if (typeof formId !== "undefined")
                    $(formId).submit();
                $(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });
    

    然后我打开确认对话框

     $("a").live("click", function () {       
        if (hasUnsavedData()) {
            $('#confirm')
             .data("anchorId", this)
             .dialog('open');
            return false;
        } else return true;
    });
    

    【讨论】:

      【解决方案2】:

      你不能,我的意思是至少在对话框之外,“警报”在“离开页面”之前执行。您需要在“对话关闭”调用后立即提醒。

      $(this).data("x","this is a test");
      $(this).dialog("close");
      alert($(this).data("x"));
      

      【讨论】:

        【解决方案3】:

        解决方案:

        Jquery Dialog Confirmation with return

        这很难找到,明智地使用它

        【讨论】:

          猜你喜欢
          • 2011-04-03
          • 2012-07-10
          • 1970-01-01
          • 1970-01-01
          • 2014-11-15
          • 2011-05-24
          • 2020-06-27
          相关资源
          最近更新 更多