西西木科技丨Shopify开发机构 2022-09-26 22:38 采纳率: 96.4%
浏览 15
已结题

等待await循环结束后自动点击对应按钮

按完#fianlatc之后,等待await循环结束后,自动点击#viewcart


<div class="container"
     id="finalform"
     style="">
<botton id="fianlatc" class="custombtn">Add To Cart</botton>
    <div class="product-boxx"
         id="product-laptop"
         style="">
        <p class="producttitle">Laptop</p>
        <p class="productprice">$79.99 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029479" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
    <div class="product-boxx"
         id="product-monitor"
         style="display:none;">
        <p class="producttitle">Monitor</p>
        <p class="productprice">$69.99 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029480" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
    <div class="product-boxx"
         id="product-lapmon"
         style="display:none;">
        <p class="producttitle">Laptop</p>
        <p class="productprice">$99.99 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029481" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
    <div class="product-boxx"
         id="product-monitor2"
         style="display:none;">
        <p class="producttitle">Laptop</p>
        <p class="productprice">$89.99 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029482" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
    <div class="product-boxx"
         id="product-light"
         style="">
        <p class="producttitle">Laptop Light</p>
        <p class="productprice">$70.00 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029483" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
    <div class="product-boxx"
         id="product-pad"
         style="">
        <p class="producttitle">Laptop pad</p>
        <p class="productprice">$39.99 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029484" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
    <div class="product-boxx"
         id="product-micro"
         style="">
        <p class="producttitle">Laptop</p>
        <p class="productprice">$39.99 USD</p>
  <form method="post" action="/cart/add">
    <input type="hidden" name="id" value="42749446029485" />
    <input type="submit" value="Add to cart" class="atcbtn" />
  </form> 
    </div>
<input type="number" id="finalprice">
<a href="/cart" class="custombtn1" id="viewcart" target="_blank">View Carts</a>
</div>
 
 
<script>
      var kvLastImg = {
        laptop: {
            default: '',
            lightyon: '',
            tabletyon: '',
            microyon: '',
            lightyontabletyon: '',
            lightyonmicroyon: '',
            tabletyonmicroyon: '',
            lightyontabletyonmicroyon: ''
        },
        monitor: {
            default: '',
            lightyon: '',
            tabletyon: '',
            microyon: '',
            lightyontabletyon: '',
            lightyonmicroyon: '',
            tabletyonmicroyon: '',
            lightyontabletyonmicroyon: ''
        },
        laptopmonitor: {
            default: '',
            lightyon: '',
            tabletyon: '',
            microyon: '',
            lightyontabletyon: '',
            lightyonmicroyon: '',
            tabletyonmicroyon: '',
            lightyontabletyonmicroyon: ''
        },
        monitormonitor: {
            default: '',
            lightyon: '',
            tabletyon: '',
            microyon: '',
            lightyontabletyon: '',
            lightyonmicroyon: '',
            tabletyonmicroyon: '',
            lightyontabletyonmicroyon: ''
        }
    }
 
 
 
    function setSum() {
        /////图片设置
        var step1option = $("input[name='equipment']:checked").val(), stepId;
        switch (step1option) {
            case 'laptop': stepId = 'step2-laptop'; break;
            case 'monitor': stepId = 'step2-monitor'; break;
            case 'laptopmonitor': stepId = 'step2-lapmoni'; break;
            case 'monitormonitor': stepId = 'step2-monitor2'; break;
        }
        var imgItem = kvLastImg[step1option];//新图片节点
        var step2Div = $('#' + stepId);//第二步对应的容器
        var addon = step2Div.find('input.optioninput:checked').map(function () { return this.id }).get().join('');//选中的addon
        if (!addon) addon = 'default';
        var src = imgItem[addon];
        console.log(src)
        $('#step4img').attr('src', src)
      
 
        /////图片设置
 
 
 
        var sum = 0;
        $('#finalform .product-boxx:visible p.productprice').each(function () {
            sum += parseFloat(this.innerText.substring(1));
        });
        sum = sum.toFixed(2);//保留2位小数,防止浮点数计算精度丢失
        $('#finalprice').val(sum)
 
 
        $('#fianlatc').unbind().click(async function () {
            var btns = $('#finalform .product-boxx:visible input.atcbtn');
            for (var i = 0; i <btns.length; i++) {
                //await控制循序请求,2秒点一个按钮
                await clickButton(btns.eq(i))
            }
        });

       setTimeout(function(){Globo.FormBuilder.showFloatingForm(document.body);},1000);
    }

    function clickButton(btn) {
       return new Promise((resolve, reject) => {
            btn.trigger('click');
           setTimeout(resolve, 1000);
        });
    }
  
</script>
  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-09-26 22:47
    关注
        $('#fianlatc').unbind().click(async function () {
            var btns = $('#finalform .product-boxx:visible input.atcbtn');
            for (var i = 0; i < btns.length; i++) {
                //await控制循序请求,2秒点一个按钮
                await clickButton(btns.eq(i))
            }
            window.open('/cart','_blank');///新窗口打开,不过由于是异步操作,可能会被拦击,你试试
        })
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月26日
  • 已采纳回答 9月26日
  • 创建了问题 9月26日

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法