【问题标题】:asp.net shopping cart update quantity in cookieasp.net 购物车更新 cookie 中的数量
【发布时间】:2014-03-03 06:17:52
【问题描述】:

在购物车网页中,我有这个列表视图来显示购物车中的物品:

 <asp:ListView ID="List" runat="server" DataKeyNames="ID">


          <table class="tbl">
                    <tr>
                      <td class="one">
                        <h4><%# Eval("ID")%></h4>
                      </td>
                      <td class="two">
                         <h4><%# Eval("Name")%></h4>
                      </td>
                      <td class="fone"><%# Eval("Total")%></td>

                      <td>
                          <asp:DropDownList runat="server" CssClass='drop' SelectedValue='<%# Eval("Qty")%>'>
                          <asp:ListItem value="1">1</asp:ListItem>
                          <asp:ListItem value="2">2</asp:ListItem>
                          <asp:ListItem value="3">3</asp:ListItem>
                          <asp:ListItem value="4">4</asp:ListItem>
                         </asp:DropDownList>
                      </td> 

                      <td class="ffour"><%# Eval("Price")%></td>
                    </tr>

            </table>

items 从 cookie 中检索。当用户将商品添加到购物车时,商品添加到此 listview 中。 我已经编写了 jquery 代码,当用户更改一件商品的数量时,总价格会自动更改。

 $('.drop').on('change', function () {
               var tr = $(this).closest('tr');
               var price = $(tr).find('.ffour').html();
               $(tr).find('.fone').html(price * $(this).val());
           });

当用户改变数量时,cookie中的数量也改变了怎么办?例如,当用户将第一行的数量从1变为2时,网站cookie中的数量从1变为2。

cookie 的名称是 'SiteCookie' 。并且有数量的产品。

【问题讨论】:

  • 请说明你在哪里使用过cookies?
  • 在 asp.net 代码隐藏中,我使用 HttpCookie currentCookie = Request.Cookies["SiteCookie"]; 读取 cookie;
  • 然后将 cookie 中的产品加载到 ArrayList 中,然后用 ArrayList 填充 Listview。一切都很好并且工作正常,但是当用户将一种产品的数量更改为 1 到 2 时,我想将此更改存储到 cookie 中。怎么样?
  • 你也可以在 jqueries 中使用 cookie ......我认为这对你的情况很有用

标签: c# jquery asp.net cookies shopping-cart


【解决方案1】:

首先拿这个js for Cookies然后

       $('.drop').on('change', function () {
           $.cookie("qty",$(this).closest('tr'))
           var price = $(tr).find('.ffour').html();
           $(tr).find('.fone').html(price * $.cookie("qty"));
       });

在页面加载时,您也可以调用 cookie...如果 cookie 有值,则执行此操作

      $(tr).find('.fone').html(price * $.cookie("qty"));

【讨论】:

  • 你能邀请我聊天吗?我解释我想要什么。
  • 是啊当然..过来this group@user3234297
猜你喜欢
  • 2019-12-25
  • 1970-01-01
  • 1970-01-01
  • 2021-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 2021-01-29
相关资源
最近更新 更多