首页 新闻 会员 周边

关于Reapeter里面的Reapeter(二)

0
悬赏园豆:20 [已解决问题] 解决于 2014-01-23 16:09

我现在要在里面的Reapeter控制一个数字增加减少:

<asp:Repeater ID="rptShopList" runat="server" OnItemDataBound="rptShopList_OnItemDataBound">
                    <ItemTemplate>
                        <div class="Itme">
                            <div class="ItmeC">
                                <ul>
                                    <asp:Repeater ID="rptProductList" runat="server">
                                        <ItemTemplate>
                                            <li class="gmSl"><a id="aAdd" runat="server" class="addNum"></a>
                                                <input id="txtBuyNum" type="text" value='<%#Eval("Count") %>' runat="server" />
                                                <a id="aRed" runat="server" class="romNum"></a></li>
                                            <li class="gmJg" id="liPrice" runat="server"><%#Eval("Price")%></li>
                                            <li class="szJf">
                                                <%#Eval("Bonus")%></li>
                                            <li class="cz"><a id="aDel" runat="server">删除</a></li>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </ul>
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>

我要通过点击aAdd控件和aRed控件来增加、减少txtBuyNum的值;

我在后台去绑定的:

        /// <summary>
        /// 购物车商品列表绑定事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptShopList_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptProductList = e.Item.FindControl("rptProductList") as Repeater;

                foreach (RepeaterItem item in rptProductList.Items)
                {
                    HtmlAnchor aAdd = item.FindControl("aAdd") as HtmlAnchor;
                    HtmlAnchor aRed = item.FindControl("aRed") as HtmlAnchor;
                    aAdd.Attributes.Add("onclick", string.Format("UpdateProductNum(1,{0})", item.ItemIndex));
                    aRed.Attributes.Add("onclick", string.Format("UpdateProductNum(2,{0})", item.ItemIndex));
                }
            }
        }

 

前台部分Jquery如下:

function UpdateProductNum(type, rowIndex) {
   var text = $(".gmSl input[type='text']").eq(rowIndex);

   if (type == 1) {
      text.val(parseInt(text.val()) + 1);
   }
   else
      text.val(parseInt(text.val()) - 1);
});

但是这样做只能点击第一行有效,其他都是无效。。。

Jquery代码应该怎么改?

应该主要是改这一句代码:

var text = $(".gmSl input[type='text']").eq(rowIndex);
以便以谢的主页 以便以谢 | 初学一级 | 园豆:119
提问于:2014-01-23 15:49
< >
分享
最佳答案
0
                    aAdd.Attributes.Add("onclick", string.Format("UpdateProductNum(1,{0})", item.ItemIndex));
                    aRed.Attributes.Add("onclick", string.Format("UpdateProductNum(2,{0})", item.ItemIndex));

改成:

                    aAdd.Attributes.Add("onclick", string.Format("UpdateProductNum(this,1,{0})", item.ItemIndex));
                    aRed.Attributes.Add("onclick", string.Format("UpdateProductNum(this,2,{0})", item.ItemIndex));


JavaScript:

function UpdateProductNum(type, rowIndex) {
   var text = $(".gmSl input[type='text']").eq(rowIndex);

改成:

function UpdateProductNum(btn,type, rowIndex) {
   var text = $(btn).parent().find(":text");

 

收获园豆:20
I,Robot | 大侠五级 |园豆:9783 | 2014-01-23 15:59

其实rowIndex都可以去掉了

I,Robot | 园豆:9783 (大侠五级) | 2014-01-23 15:59

@DiQiSoft.Com: 谢谢,正解,解决了^_^我那样为什么不行?

以便以谢 | 园豆:119 (初学一级) | 2014-01-23 16:09
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册