当前位置: 首页 > news >正文

网站建设的成本分析网站建设项目方案模板

网站建设的成本分析,网站建设项目方案模板,2345是哪个公司的软件,推广网站有效的免费方法下面是一个更全面的商品购物系统示例,包含新增商品、商品的增加删除以及结算找零的功能。这个系统使用HTML和JavaScript实现。 1.功能说明: 这个应用程序使用纯HTML和JavaScript实现。 包含一个商品列表和一个购物车区域。商品列表中有几个示例商品&a…

下面是一个更全面的商品购物系统示例,包含新增商品、商品的增加删除以及结算找零的功能。这个系统使用HTML和JavaScript实现。

1.功能说明:

这个应用程序使用纯HTML和JavaScript实现。

  • 包含一个商品列表和一个购物车区域。
  • 商品列表中有几个示例商品,每个商品都有一个“加入购物车”按钮。
  • 点击“加入购物车”按钮后,商品会被添加到购物车中,并更新购物车显示。
  • 购物车中列出了所有已添加的商品,并计算总价。
  • 每个购物车项都有一个“移除”按钮,可以移除该商品。
  • 结算部分包含一个支付金额输入框和一个结算按钮。
  • 输入支付金额后点击结算按钮,会计算找零并弹出提示框显示结算信息,然后清空购物车。
  • 新增商品部分包含输入框用于输入新的商品名称和价格,以及一个“新增商品”按钮。
  • 点击“新增商品”按钮后,新的商品会被添加到商品列表中。

2.代码展示

<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>商品购物系统</title><style>body {font-family: Arial, sans-serif;background-color: #f4f4f9;margin: 0;padding: 20px;}.container {display: flex;justify-content: space-between;}.product-list, .cart {width: 45%;background-color: white;padding: 20px;border-radius: 10px;box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);}h1 {text-align: center;}.product-item, .cart-item {display: flex;justify-content: space-between;align-items: center;padding: 10px;border-bottom: 1px solid #eee;}.product-item:last-child, .cart-item:last-child {border-bottom: none;}.product-item button, .cart-item button {padding: 5px 10px;background-color: #007bff;color: white;border: none;border-radius: 5px;cursor: pointer;}.product-item button:hover, .cart-item button:hover {background-color: #0056b3;}.total {margin-top: 20px;font-size: 18px;font-weight: bold;}.checkout-section {margin-top: 20px;}.checkout-section input[type="number"] {width: 100px;padding: 5px;border: 1px solid #ccc;border-radius: 5px;margin-right: 10px;}.checkout-section button {padding: 5px 10px;background-color: #28a745;color: white;border: none;border-radius: 5px;cursor: pointer;}.checkout-section button:hover {background-color: #218838;}.add-product-section {margin-top: 20px;}.add-product-section input[type="text"], .add-product-section input[type="number"] {width: 150px;padding: 5px;border: 1px solid #ccc;border-radius: 5px;margin-right: 10px;}.add-product-section button {padding: 5px 10px;background-color: #ffc107;color: white;border: none;border-radius: 5px;cursor: pointer;}.add-product-section button:hover {background-color: #e0a800;}</style>
</head>
<body><div class="container"><div class="product-list"><h1>商品列表</h1><div id="product-items"></div><div class="add-product-section"><input type="text" id="new-product-name" placeholder="商品名称" required><input type="number" id="new-product-price" placeholder="价格" min="0" step="any" required><button onclick="addNewProduct()">新增商品</button></div></div><div class="cart"><h1>购物车</h1><div id="cart-items"></div><div class="total" id="total-price">总价: ¥0.00</div><div class="checkout-section"><input type="number" id="payment" placeholder="支付金额" min="0" step="any" required><button onclick="checkout()">结算</button></div></div></div><script>let products = [{ name: '苹果', price: 5 },{ name: '香蕉', price: 3 },{ name: '橙子', price: 4 }];let cart = [];function updateProductList() {const productItemsDiv = document.getElementById('product-items');productItemsDiv.innerHTML = '';products.forEach((product, index) => {const itemDiv = document.createElement('div');itemDiv.className = 'product-item';itemDiv.innerHTML = `<span>${product.name}</span><span>¥${product.price.toFixed(2)}</span><button οnclick="addToCart('${product.name}', ${product.price})">加入购物车</button>`;productItemsDiv.appendChild(itemDiv);});}function addToCart(name, price) {const item = { name, price };cart.push(item);updateCartDisplay();}function updateCartDisplay() {const cartItemsDiv = document.getElementById('cart-items');cartItemsDiv.innerHTML = '';let totalPrice = 0;cart.forEach((item, index) => {const itemDiv = document.createElement('div');itemDiv.className = 'cart-item';itemDiv.innerHTML = `<span>${item.name}</span><span>¥${item.price.toFixed(2)}</span><button οnclick="removeFromCart(${index})">移除</button>`;cartItemsDiv.appendChild(itemDiv);totalPrice += item.price;});document.getElementById('total-price').textContent = `总价: ¥${totalPrice.toFixed(2)}`;}function removeFromCart(index) {cart.splice(index, 1);updateCartDisplay();}function checkout() {if (cart.length === 0) {alert('购物车为空,请先添加商品!');return;}const payment = parseFloat(document.getElementById('payment').value);const totalPrice = cart.reduce((sum, item) => sum + item.price, 0);if (isNaN(payment) || payment < totalPrice) {alert('支付金额不足,请重新输入!');return;}const change = payment - totalPrice;alert(`结算成功!总价: ¥${totalPrice.toFixed(2)}\n支付金额: ¥${payment.toFixed(2)}\n找零: ¥${change.toFixed(2)}`);cart = [];updateCartDisplay();document.getElementById('payment').value = '';}function addNewProduct() {const newName = document.getElementById('new-product-name').value.trim();const newPrice = parseFloat(document.getElementById('new-product-price').value);if (!newName || isNaN(newPrice) || newPrice <= 0) {alert('请输入有效的商品名称和价格!');return;}products.push({ name: newName, price: newPrice });updateProductList();document.getElementById('new-product-name').value = '';document.getElementById('new-product-price').value = '';alert(`商品 "${newName}" 已成功添加`);}// 初始化商品列表updateProductList();</script>
</body>
</html>

3.效果展示

在这里插入图片描述

http://www.yayakq.cn/news/161811/

相关文章:

  • 主流媒体网站建设建设设计项目备案在哪个网站
  • 北京给网站做系统的公司网络科技公司起名大全免费
  • 检测网站是否做了301网络工程师报考入口
  • 网站开发资格证书做房产经纪人要自己花钱开网站吗
  • 大型网站建设翻译英文做软件的中介网站
  • 网站备案号收回wordpress高级模板下载
  • 潍坊做网站哪家公司最好企业开办网站
  • 北京建设局网站一般制作一个app需要多少钱
  • 宠物之家网站开发施工企业负责人带班检查计划
  • 东营建设信息网站做游戏网站要多少钱
  • c2c网站有哪些?我自己做个网站怎么做
  • 河西做网站网站制作com
  • 陕西省国家示范校建设专题网站企业网站建站哪家好
  • 法律顾问 网站 源码本科毕业 做网站编辑
  • 北京做网站成都网站建设创意
  • 天津品牌网站建设好处企业网页制作公司
  • 石林彝族网站建设扬州seo招聘
  • 顶呱呱网站做的怎么样深圳工程建设服务网
  • 需要前置审批的网站百度做网站需要多少钱
  • 宝安网站设计案例建站工具指北
  • 仙居住房和城乡建设局网站做网站反复修改
  • 淄博网站制作高端网络wordpress国内访问不了
  • 哪些网站可以做任务wordpress移除注册登录界面图标
  • 石家庄商城网站制作普通电脑如何做网站服务器吗
  • 西安优秀的集团门户网站建设费用镇江公交优化
  • 地方门户网站管理系统博客社区类网站模板下载
  • 网站开发的工作需要什么材料网络品牌营销案例
  • 免费做网站怎么做网站链接seo优化或网站编辑
  • 网站建设板块免费下载小程序微商城定制开发
  • 做网站用的浏览器有哪些益阳做网站公司