日期:2014-05-18  浏览次数:20534 次

GridView购物车使用js进行产品数量的增加问题
我用GridView和js做的购物车产品数量的加减 可是当产品个数为一行时 产品的总价的值不变只有小计的值变化 
另一个问题是 产品数量使用加号和减号进行改变后 跳转到订单那页时 购物中产品的数量为1 哪位前辈麻烦给看看吧
下面是代码
aspx页 code
JScript code

  <script type="text/javascript">
      function jia(ele) {
          tr = ele.parentNode;
          while (tr.nodeType != 1 || tr.tagName != "TR") tr = tr.parentNode;
          num = tr.cells[5].getElementsByTagName("input")[0];
          var t = parseInt(num.value, 10);
          if (isNaN(t)) num.value = 0;
          else num.value = t + 1;
          countRow(tr)
      }
      function jian(ele) {
          tr = ele.parentNode;
          while (tr.nodeType != 1 || tr.tagName != "TR") tr = tr.parentNode;
          num = tr.cells[5].getElementsByTagName("input")[0];
          var t = parseInt(num.value, 10);
          if (isNaN(t)) num.value = 0;
          else {
              if (t < 1) return;
              num.value = t - 1;
          }
          countRow(tr)
      }
      function bian(ele) {
          tr = ele.parentNode;
          while (tr.nodeType != 1 || tr.tagName != "TR") tr = tr.parentNode;
          countRow(tr)
      }

      function countRow(row) {
          price = parseFloat(row.cells[3].innerHTML);
          if (isNaN(price)) {
              row.cells[6].innerHTML = "0"
              return;
          }
          num = row.cells[5].getElementsByTagName("input")[0];
          t = parseInt(num.value, 10);
          if (isNaN(t)) t = 0;
          row.cells[6].innerHTML = roundPrice(price * t);
          CountAll();
      }
      function CountAll() {
          var total = 0;
          table = document.getElementById('<%=GridView1.ClientID %>');
          if (table.rows.length < 3) return;
          for (i = 1; i < table.rows.length; i++) {
              p = parseFloat(table.rows[i].cells[6].innerHTML);
              if (isNaN(p)) p = 0;
              total += p;
           
          }
          document.getElementById('<%=TotalPrice.ClientID %>').innerHTML = roundPrice(total);
        
      }

      function roundPrice(x) {
          return Math.round(x * 100) / 100;
      }
  </script>

<body>
                 <td>
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        DataKeyNames="ProductCode" Width="1052px" 
                         onrowdeleting="GridView1_RowDeleting" CssClass="No" 
                         onrowdatabound="GridView1_RowDataBound" >
                        <Columns>
                            <asp:BoundField DataField="ProductCode" HeaderText="商品编号"  >
                            </asp:BoundField>
                            <asp:ImageField DataAlternateTextField="ProImage" DataImageUrlField="ProImage" 
                                DataImageUrlFormatString="../UploadFile/img/{0}" HeaderText="商品图片">
                            </asp:ImageField>
                             <asp:BoundField DataField="ProductName" HeaderText="商品名称" />
                             <asp:TemplateField HeaderText="价格">
                            <ItemTemplate>
                            <%#Eval("MallPrice") %>
                            </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="Intergral" HeaderText="赠送积分" />
                            <asp:TemplateField HeaderText="商品数量">
                              <ItemTemplate>