JQuery simulates shopping cart orders using coupons JQ

When you're lonely, you'll be accompanied by a dog 2022-02-13 06:26:59 阅读数:119

jquery simulates shopping cart orders
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2> Welcome to my order </h2>
<table>
<tr>
<td> Name of commodity </td>
<td> Wellington steak </td>
</tr>
<tr>
<td> item pricing </td>
<td><div class="price">50</div></td>
</tr>
<tr>
<td> The number </td>
<td><button class="add_btn">+</button>
<span style="display:inline-block;text-align:center;background-color: #999999; width:40px;">1</span>
<button class="minus">—</button>
</td>
</tr>
<tr>
<td> Coupon </td>
<td><select name="" id="" class="select">
<option value="0">-- Please select --</option>
{volist name="myCoupons" id="v"}
<option value="{$v.id}" c_money="{$v.coupon.c_money}"
c_satisfy="{$v.coupon.c_satisfy}"
c_condition = "{$v.coupon.c_condition}"
>{$v.coupon.c_name}</option>
{/volist}
</select></td>
</tr>
<tr>
<td> Total sum </td>
<td> <font></font></td>
</tr>
<tr>
<td> Settlement amount </td>
<td></td>
</tr>
</table>
</body>
</html>
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
// Commodity price
var totalPrice;
var price = parseInt($('.price').text());// item pricing
// Page load event
$(function () {
var num = parseInt($('span').text());
// The total amount of goods
$('font').text(num*price);
})
// Packaged coupon method
function coupon(){
// Determine whether to use coupons
var select = $('.select option:selected').val();
// Use coupons
if (select != 0)
{
// Coupon face value
var c_money = parseInt($('option:selected').attr('c_money'));
// Conditions for coupon use for example : full 100 reduce 20 Here it means 100;
var c_satisfy = parseInt($('option:selected').attr('c_satisfy'));
// Types of coupons
var c_condition = parseInt($('option:selected').attr('c_condition'));
// 1、 Use... Unconditionally , The order amount shall not be less than the face value of the coupon
if (c_condition == 1)
{
if (totalPrice < c_money)
{
alert(' The amount of the coupon is at least equal to the amount of the coupon ');
// throw " No further execution ";
return;
}
}
// 2. Full discount coupon
if (c_condition == 2)
{
// Judge whether the order amount is greater than the full minus condition amount
if (totalPrice < c_satisfy)
{
alert(' The coupon does not meet ');
// Return the total amount of goods
$('font').text(totalPrice);
return false;
}
}
// Total amount of coupons used
totalPrice = totalPrice - c_money;
$('font').text(totalPrice);
} else {
// Total amount of unused coupons
$('font').text(totalPrice);
}
}
// Event triggered when the quantity of goods increases
$('.add_btn').click(function () {
// The number
var shops = parseInt($('span').text());
shops = shops + 1;
$('span').text(shops);
totalPrice = shops * price;
// Call the encapsulated coupon method
coupon();
})
// Event triggered when the quantity of goods decreases
$('.minus').click(function () {
// The number
var shops = parseInt($('span').text());
if(shops > 1)
{
shops = shops-1;
$('span').text(shops);
totalPrice = shops * price;
coupon();
}
})
// Drop down box to change the event
$('select').change(function () {
// The total amount of goods
var shops = parseInt($('span').text());
totalPrice = shops*price;
// Use coupons
coupon();
})
</script>

copyright:author[When you're lonely, you'll be accompanied by a dog],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130626560905.html