1

我想对 asp.net 按钮单击进行 jquery 确认,该按钮位于中继器内,但下面的代码不起作用。

它甚至没有进入函数 Confirmation()

当页面加载时,confirmDialog div 是可见的,就像它是一个常规的 div 元素而不是弹出窗口一样,这不再是问题,但其余部分保持不变

我错过了什么?

<asp:Content ID="Content2" ContentPlaceHolderID="AdminHead" runat="server">
   <script lang="javascript" type="text/javascript">
       $(function () {
           $("#confirmDialog").dialog({
               autoOpen: false,
               modal: true,
               buttons: {
                   'Confirm': function () {
                       $(this).dialog('close');
                       return true;
                   },
                   'Cancel': function () {
                       $(this).dialog('close');
                       return false;
                    }
                }
            });
            function Confirmation() { 
            alert("IN");

                $('#confirmDialog')
            .dialog('option', 'onOk', $(this).attr('href'))
            .dialog('open');
            }
        });
    </script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="AdminContentPlaceHolder" runat="server">

<div id="confirmDialog">
    <p>ARE YOU SURE YOU WANT TO CONFIRM THIS ACTION?</p>
</div>
<asp:Repeater ID="Repeater1" runat="server">
   <HeaderTemplate>
        <div class="repeaterItem">
            <table id="AdminTable">
              .
              .
              .
    </HeaderTemplate>
    <ItemTemplate>
              .
              .
              .
              <asp:Button ID="DeleteButton" CssClass="delete" OnClick="ClickDelete" OnClientClick="Confirmation();return false;" runat="server"
                    Text="DELETE" CommandArgument="<%#(Container.DataItem as TagObject).ID %>" ClientIDMode="AutoID" />
            </th>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
              .
              .
              .
        </table></div>
    </FooterTemplate>
</asp:Repeater>
</asp:Content>

-------------------------------------问题已解决---------- --------------------

我的最终代码:

    <asp:Content ID="Content2" ContentPlaceHolderID="AdminHead" runat="server">
   <script lang="javascript" type="text/javascript">
    var deleteButton;
    $(function () {
        $("#confirmDialog").dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                'Confirm': function () {
                    $(this).dialog('close');
                    __doPostBack($(deleteButton).attr('name'), '');
                },
                'Cancel': function () {
                    $(this).dialog('close');
                    callback(false);
                }
            }
        });
    });
    function Confirmation() {
        deleteButton = this;
            $('#confirmDialog').dialog('open');
        }
</script>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="AdminContentPlaceHolder" runat="server">

<div id="confirmDialog">
    <p>ARE YOU SURE YOU WANT TO CONFIRM THIS ACTION?</p>
</div>
<asp:Repeater ID="Repeater1" runat="server">
   <HeaderTemplate>
        <div class="repeaterItem">
            <table id="AdminTable">
              .
              .
              .
    </HeaderTemplate>
    <ItemTemplate>
              .
              .
              .
              <asp:Button ID="DeleteButton" CssClass="delete" OnClick="ClickDelete" OnClientClick="Confirmation();" runat="server"
                    Text="DELETE" CommandArgument="<%#(Container.DataItem as TagObject).ID %>" ClientIDMode="AutoID" />
            </th>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
              .
              .
              .
        </table></div>
    </FooterTemplate>
</asp:Repeater>
</asp:Content>
4

1 回答 1

1

首先将确认功能从块中取出。编辑使其实际工作:

<script lang="javascript" type="text/javascript">
    $(function () {
        $("#confirmDialog").dialog({
            autoOpen: false,
            modal: true,
            buttons: {
                'Confirm': function () {
                    $(this).dialog('close');
                    return true;
                },
                'Cancel': function () {
                    $(this).dialog('close');
                    return false;
                }
            }
        });

    });
    function Confirmation() {
        alert("IN");

        $('#confirmDialog').dialog('open');
    }
</script>


<asp:Button ID="DeleteButton" CssClass="delete" OnClick="ClickDelete" OnClientClick="Confirmation();return false;"
    runat="server" Text="DELETE" CommandArgument="asd" ClientIDMode="AutoID" />
于 2013-04-17T09:06:17.313 回答