簡體   English   中英

asp.net購物車更新cookie中的數量

[英]asp.net shopping cart update quantity in cookie

在購物車網頁中,我具有此列表視圖以顯示購物車中的物品:

 <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>

從cookie檢索項目。當用戶將項目添加到購物車時,項目已添加到此listview。 我已經編寫了jQuery代碼,當用戶更改一件商品的數量時,totalprice已自動更改。

 $('.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'。 並且具有產品數量的數量。

首先,將此js用作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"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM