按完#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>