1

我正在尝试使用以下代码打开一个 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() 进行重定向。

4

3 回答 3

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;
});
于 2013-04-25T14:50:03.407 回答
0

解决方案:

带有返回的Jquery对话框确认

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

于 2013-08-27T19:47:31.750 回答
0

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

$(this).data("x","this is a test");
$(this).dialog("close");
alert($(this).data("x"));
于 2013-04-25T10:49:51.123 回答