JQuery中的ConfirmDialog()在按钮上单击自动关闭

时间:2018-07-04 06:44:26

标签: javascript jquery asp.net vb.net confirm

我在ConfirmDialog()点击事件中调用的JQuery中有一个asp:button函数。它工作正常,但是当我单击button时,会调用ConfirmDialog()自动关闭对话框,而无需用户单击。
我用过:

function ConfirmDialog() {

                $('<div></div>').appendTo('body')
    .html('<div><h4>' + 'Do you wanto to see previous data' + '?</h4></div>')
    .dialog({
        modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
        width: 'auto', resizable: false,
        buttons: {
            Yes: function () {
                //                $(obj).removeAttr('onclick');
                //                $(obj).parents('.Parent').remove();

                $('body').append('<h1>Confirm Dialog Result: <i>Yes</i></h1>');
                $(this).dialog("close");
                confirm_value.value = "Yes";
            },
            No: function () {
                $('body').append('<h1>Confirm Dialog Result: <i>No</i></h1>');
                $(this).dialog("close");
                confirm_value.value = "No";
            }
        },
        close: function (event, ui) {
            $(this).remove();
        }
    });
                document.forms[0].appendChild(confirm_value);
            });

我知道页面刷新正在关闭它。然后,我尝试使用$(document).ready()停止自动关闭,但无法正常工作:

function ConfirmDialog() {
            $(document).ready(function () {

                $('<div></div>').appendTo('body')
    .html('<div><h4>' + 'Do you wanto to see previous data' + '?</h4></div>')
    .dialog({
        modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
        width: 'auto', resizable: false,
        buttons: {
            Yes: function () {
                //                $(obj).removeAttr('onclick');
                //                $(obj).parents('.Parent').remove();

                $('body').append('<h1>Confirm Dialog Result: <i>Yes</i></h1>');
                $(this).dialog("close");
                confirm_value.value = "Yes";
            },
            No: function () {
                $('body').append('<h1>Confirm Dialog Result: <i>No</i></h1>');
                $(this).dialog("close");
                confirm_value.value = "No";
            }
        },
        close: function (event, ui) {
            $(this).remove();
        }
    });
                document.forms[0].appendChild(confirm_value);
            });
        }; 

这是我的按钮:

<asp:Button ID="btnConfrm" runat="server" Text="View" ForeColor="Black" Width="80px"
                        CssClass="button" Height="30px" ValidationGroup="btn" OnClick="OnConfirm" OnClientClick="ConfirmDialog()"/>

1 个答案:

答案 0 :(得分:-1)

按钮语法似乎已关闭。而且document.ready对您放置它的位置没有帮助。

您可以发布onConfirm代码(c#)吗?

如果您尝试这样做会怎样?

function ConfirmDialog() {

                $('<div></div>').appendTo('body')
    .html('<div><h4>' + 'Do you wanto to see previous data' + '?</h4></div>')
    .dialog({
        modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
        width: 'auto', resizable: false,
        buttons: [{
            Yes: function () {
                //                $(obj).removeAttr('onclick');
                //                $(obj).parents('.Parent').remove();

                $('body').append('<h1>Confirm Dialog Result: <i>Yes</i></h1>');
                $(this).dialog("close");
                confirm_value.value = "Yes";
            },
            No: function () {
                $('body').append('<h1>Confirm Dialog Result: <i>No</i></h1>');
                $(this).dialog("close");
                confirm_value.value = "No";
            }
        }],
        close: function (event, ui) {
            $(this).remove();
        }
    });
                document.forms[0].appendChild(confirm_value);

        };