在jquery中删除div

时间:2014-04-07 12:05:34

标签: javascript asp.net

我有一个转发器,其中有一个按钮。并且在该按钮的onclientclick上应删除相应的div,然后使用ajax删除db查询。

当我正在做div.remove()它的工作正常。但当我把删除代码放在ajax的成功部分..它不工作..但页面刷新其工作正常..

我的代码是......

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >
                        <ItemTemplate>
                            <div class="grid_4" data-gen="afc" data-gen-offset="bottom-in-view" id='<%#Eval("Id") %>'>
                                <a class="services-block" href="#">
                                    <ul class="icon">
                                        <li class="fontawesome-icon large circle-two fa fa-laptop"></li>
                                        <li class="fontawesome-icon large circle-deg-two fa fa-laptop"></li>
                                    </ul>
                                    <p>
                                        <asp:Label ID="lblGameTitle" runat="server" Text='<%# Eval("GameName") %>'></asp:Label></p>
                                    <div class="text">
                                        <asp:Label ID="lblOpponent" runat="server" Text='<%# Eval("OpponentOne") + "  Vs.  "+ Eval("OpponentTwo") %>'></asp:Label>
                                        <br />
                                        <asp:Label ID="lblDateTime" runat="server" Text='<%# "Date : "+ Eval("GameDate") + "<br />Time : " + Eval("GameTime") %>'></asp:Label>
                                        <br />

                                        <asp:RadioButton ID="rbtnBlue" runat="server" Text="High" GroupName="UrlColor" Checked="true" />
                                        <asp:RadioButton ID="rbtnRed" runat="server" Text="Low" GroupName="UrlColor" />


                                        <asp:Button ID="btnOpponentOne" runat="server" Text='<%# Eval("OpponentOne") %>' OnClientClick="opponentOne(this);"/>
                                        <asp:Button ID="btnOpponentTwo" runat="server" Text='<%# Eval("OpponentTwo") %>' OnClientClick="opponentTwo(this);"/>
                                        <asp:Button ID="btnDraw" runat="server" Text="Draw" OnClientClick="Draw(this);"/>
                                        <br />
                                    </div>
                                </a>
                            </div>
                            <asp:HiddenField ID="gid" runat="server" Value='<%# Eval("ID") %>' />
                            <asp:HiddenField ID="opOne" runat="server" Value='<%# Eval("OpponentOne") %>' />
                            <asp:HiddenField ID="opTwo" runat="server" Value='<%# Eval("OpponentTwo") %>' />
                        </ItemTemplate>
                    </asp:Repeater>
                   <%-- <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />--%>

                </ContentTemplate>
            </asp:UpdatePanel>

和js是......

function opponentOne(btn) {
            var s = btn.id;
            var start = s.indexOf("btnOpponentOne");
            var end = s.lastIndexOf("_");
            sub = s.substring(start, end);
            s = s.replace(sub, "opOne");
            var hidden = document.getElementById(s);
            var id = hidden.value;  /* option */
            //alert(id);
            var divId = aaaa1(btn);
            //alert(divId);
            var check = CheckRadio(btn);
            //alert(check);
            var tid = getParameterByName('tid');
            //alert(tid);
            var inputText = id + "~" + divId + "~" + check+"~"+tid;    /* option + div id(id) + high/low */
            /* database connection */
            if (confirm('Are your sure ?')) {
                $.ajax({
                    type: "POST",
                    url: "/play_match.aspx/AddPrediction",
                    data: '{\'InputText\':\'' + inputText + '\'}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (response.d == "Success") {
                            alert('done..............'+divId);
                            $('#' + divId).remove();
                        }
                    },
                    failure: function (response) {
                        alert('fail');
                        alert(response.d);
                    },
                    error: function (response) {
                        alert('error');
                        alert(response.d);`enter code here`
                    }
                });
            }

        }

2 个答案:

答案 0 :(得分:0)

这是因为updatepanel。请参阅此链接以获得清晰的图片http://www.codeproject.com/Articles/534587/ASP-NET-jQuery-is-not-Working-in-UpdatePanels

答案 1 :(得分:0)

您必须显式刷新更新面板才能刷新UI。尝试使用__doPostBack(UpdatePanel1,'');更新它。祝你好运。