0

现在我在asp.net中使用一个消息框但是我想用jquery来做同样的事情

        var DialogResult = MessageBox.Show("Do you want to create the File ?", "Start Invoicing", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        if (DialogResult == DialogResult.Yes)
        {
           //perform some action
        }
        else
        {
         //this
        }

这可以通过jquery实现吗?可以根据我要执行的内容更改 jquery 框的文本吗

请帮忙

 <script type="text/javascript">
    $(document).ready(function () {
        $('#cmdShowDialog').click(function (event) {
            event.preventDefault();
            var $dialog = $('<div>Dynamic Dialog with Buttons.</div>')
            .dialog
            ({
                title: 'Cancel',
                width: 300,
                height: 200,
                buttons:
                [{
                    text: "Yes",
                    click: function () {
                        $dialog.dialog('close');
                    }
                },
                {
                    text: "Cancel",
                    click: function () {
                        $dialog.dialog('close');
                    }
                }]
            });
        });
    });
</script>

   <asp:Button ID="cmdShowDialog" runat="server" Text="Show Dialog" />

已经尝试使用它,但我应该如何继续......

4

1 回答 1

3

你可以做这样的事情......
javascript:

<script type="text/javascript">
    function dialogYesNoCancel(btn1func, btn2func) {
        $("#dialogMessage").dialog({
            resizable: false,
            height: 140,
            modal: true,
            buttons: {
                Cancel: function () {

                    $(this).dialog("close");
                },
                No: function () {

                    $(this).dialog(btn2func());
                    $(this).dialog("close");

                },
                Yes: function () {
                    $(this).dialog(btn1func());
                    $(this).dialog("close");
                }
            }
        });
    };

    function func1() {
        $("#Button1").click();
    }

    function func2() {
        $("#Button2").click();
    }
</script>

ASPX:

<asp:Button ID="Button1" clientidmode="Static" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Button ID="Button2" clientidmode="Static" runat="server" Text="Button" onclick="Button2_Click" />

CS:

protected void Page_Load(object sender, EventArgs e)
    {       
        ScriptManager.RegisterStartupScript(this, this.Page.GetType(), Guid.NewGuid().ToString(), "dialogYesNoCancel(func1, func2)", true);
    }



    protected void Button1_Click(object sender, EventArgs e)
    {
        //do something
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        //do something
    }
于 2012-10-14T14:50:42.177 回答