溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

web如何實(shí)現(xiàn)批量購(gòu)買(mǎi)勾選的同時(shí)顯示合計(jì)數(shù)

發(fā)布時(shí)間:2021-10-21 09:35:14 來(lái)源:億速云 閱讀:118 作者:小新 欄目:web開(kāi)發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)web如何實(shí)現(xiàn)批量購(gòu)買(mǎi)勾選的同時(shí)顯示合計(jì)數(shù),小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

在做批量購(gòu)買(mǎi)時(shí),我們需要點(diǎn)選需要的商品,然后點(diǎn)批量購(gòu)買(mǎi)。

每一次點(diǎn)選,下面立即計(jì)算出合計(jì)的數(shù)量和金額。

主要代碼如下:

1,2圖為 后臺(tái)設(shè)置管理權(quán)限,勾選時(shí)的代碼??陕赃^(guò)。

<div class="form-group">
   <label class="col-sm-2 control-label"></label>
   <div class="col-sm-10">
   <volist name="list" id="vc">
      <h6 class="text-danger">{$vc['classname']}</h6>
      <volist name="vc['rule']" id="vo">
      <label >
         <input type="checkbox" name="rules[]" value="{$vo.id}" />{$vo.title}
      </label>
      </volist>
   </volist>
   </div>
</div>
$(function(){
   $("#selected").click(function(){
      $("input[name='rules[]']").each(function(){
         $(this).prop('checked', true);
      });
   });
   $("#cancel").click(function(){
      $("input[name='rules[]']").each(function(){
         $(this).prop('checked', false);
      });
   });
});



---


這是批量購(gòu)買(mǎi)。。

<volist name="list" id="vo">
<tr>
   <td >
      {$key+1}
   </td>
   <td>{$vo.username}</td>
   <td>{$vo.price}</td>
   <td>{$vo.num}</td>
   <td>{$vo.addtime|date="Y-m-d H:i:s",###}</td>
   <td>{$vo.pricenum}</td>
   <td>
      <input type="checkbox" name="oid[]" id="oid{$vo.id}" value="{$vo.id}">
   </td>
   <td><a link="{:U('Points/pvbuy',array('id'=>$vo['id']))}" class="action">購(gòu)買(mǎi)</a></td>
</tr>
</volist>
$("#checkall").click(function(){
           $("input[name='oid[]']").each(function(){
               this.checked = true;
           });
      docal();
   });

       $("#checkallno").click(function(){
           $("input[name='oid[]']").each(function(){
               this.checked = false;
           });
           $('#total_pv').html('0');
           $('#total_dg').html('0');

       });

       // 計(jì)算
       function docal(){
           var formData = $('#ajaxForm').serialize();

           // jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)
           $.ajax({
               type: 'POST',
               url: "{:U('Points/docal')}",
               data: formData,
               dataType: 'json',
               success: function(re){
                   if(re.code == 1){
                       // 返回總數(shù)量,總金額
                       // layer.alert(re.cal.num);
                       $('#total_pv').html(re.cal.num);
                       $('#total_dg').html(re.cal.usedgcash);
                   }
               },
               error:function(){
                   layer.alert('error');
               }
           });
           return false;

   }

       // 當(dāng)選擇框被點(diǎn)選取時(shí)。
       $("input[id*='oid']").change(function() {
           /*alert($(this).attr("id"));
           alert($(this).val());*/
      docal();
       });

   $(".action").click(function(){
      var buyLink=$(this).attr("link"),$this = $(this);

      layer.confirm('你確定要購(gòu)買(mǎi)嗎?',{title:'操作提示'}, function(index){
         $.post(buyLink,function(data){
            if(data.code == 1){
               layer.alert(data.message, function(){
                  window.location.reload();
               });
            }else{
               layer.alert(data.message);
            }
         });
         layer.close(index);
      });
   });
});

主要是這個(gè) change,找了很久哇。

關(guān)于“web如何實(shí)現(xiàn)批量購(gòu)買(mǎi)勾選的同時(shí)顯示合計(jì)數(shù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

web
AI