HTML 实现购物网站

news/2024/5/13 16:51:05/文章来源:https://blog.csdn.net/qq_48516121/article/details/127264963

一、程序代码:

1.HTML代码

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>结算清单</title><script src="js.js"></script><link rel="stylesheet" href="qd.css"></head>
<body>
<table id="cartTable"><thead><tr><th><label><input id="selectAll" class="check-all check" type="checkbox"/>&nbsp;全选</label></th><th>序号</th><th>商品</th><th>书籍名称</th><th>分类</th><th>出版日期</th><th>价格</th><th>数量</th><th>小计</th><th>操作</th></tr></thead><tbody><tr><td class="checkbox"><input id="item" class="check-one" type="checkbox" onclick="getStart()"/></td><td>1</td><td class="goods"><img src="images/phone1.jpg" alt="" /><span>jQuery实战</span></td><td class="sm">jQuery实战</td><td>技术</td><td class="sj">2015-11-19</td><td class="price">35.00</td><td class="count"><span class="reduce">-</span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">35.00</td><td class="operation"><span class="delete">删除</span></td></tr><tr><td class="checkbox"><input id="item" class="check-one" type="checkbox" onclick="getStart()"/></td><td>2</td><td class="goods"><img src="images/phone1.jpg" alt="" /><span>jQuery实战2</span></td><td class="sm">jQuery实战2</td><td>技术</td><td class="sj">2015-11-19</td><td class="price">35.00</td><td class="count"><span class="reduce">-</span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">35.00</td><td class="operation"><span class="delete">删除</span></td></tr><tr><td class="checkbox"><input id="item" class="check-one" type="checkbox" onclick="getStart()"/></td><td>3</td><td class="goods"><img src="images/phone2.jpg" alt="" /><span>红楼梦</span></td><td class="sm">红楼梦</td><td>文学</td><td class="sj">2015-11-19</td><td class="price">35.00</td><td class="count"><span class="reduce">-</span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">35.00</td><td class="operation"><span class="delete">删除</span></td></tr><tr><td class="checkbox"><input id="item" class="check-one" type="checkbox" onclick="getStart()"/></td><td>4</td><td class="goods"><img src="images/phone2.jpg" alt="" /><span>红楼梦2</span></td><td class="sm">红楼梦2</td><td>文学</td><td class="sj">2015-11-19</td><td class="price">35.00</td><td class="count"><span class="reduce">-</span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">35.00</td><td class="operation"><span class="delete">删除</span></td></tr><tr><td class="checkbox"><input id="item" class="check-one" type="checkbox" onclick="getStart()"/></td><td>5</td><td class="goods"><img src="images/phone3.jpg" alt="" /><span>生活的书</span></td><td class="sm">生活的书</td><td>生活</td><td class="sj">2015-11-19</td><td class="price">35.00</td><td class="count"><span class="reduce">-</span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">35.00</td><td class="operation"><span class="delete">删除</span></td></tr><tr><td class="checkbox"><input id="item" class="check-one" type="checkbox" onclick="getStart()"/></td><td>6</td><td class="goods"><img src="images/phone3.jpg" alt="" /><span>生活的书2</span></td><td class="sm">生活的书2</td><td>生活</td><td class="sj">2015-11-19</td><td class="price">35.00</td><td class="count"><span class="reduce">-</span><input class="count-input" type="text" value="1" /><span class="add">+</span></td><td class="subtotal">35.00</td><td class="operation"><span class="delete">删除</span></td></tr></tbody>
</table><div class="foot" id="foot"><div class="fr closing" onclick="showTotal()">结 算</div><div class="fr total">合计:¥<span id="priceTotal">0.00</span></div><div class="fr selected">已选商品<span id="selectedTotal">0</span>件</div>
</div>
</body>
</html>

1.2JS代码

window.onload = function() {var oSelect = document.getElementById("selectAll");var aItems = document.getElementsByClassName("check-one");var oSum = document.getElementById("priceTotal");var oGoods = document.getElementById("selectedTotal");// 全选oSelect.onclick = function() {if (oSelect.checked) {for (var i = 0; i < aItems.length; i++) {if (aItems[i].checked) {} else {oSelect.checked = true;aItems[i].checked = true;getStart();}}} else {//全消for (var i = 0; i < aItems.length; i++) {if (aItems[i].checked) {aItems[i].checked = false;oSum.innerText = 0;oGoods.innerText = 0;} else {}}}}
}function getStart() {var oSelect = document.getElementById("selectAll");var aItems = document.getElementsByClassName("check-one");var oSum = document.getElementById("priceTotal");var oGoods = document.getElementById("selectedTotal");var aSubtotal = document.getElementsByClassName("subtotal");var aCountInput = document.getElementsByClassName("count-input");var a = 0;for (var i = 0; i < aItems.length; i++) {if (aItems[i].checked) {chooseIt(i);a++;if (a == 3) {oSelect.checked = true; //当所有选项都选到时,全选按钮自动勾选}} else {oSelect.checked = false; //任意一个选项没勾选,全选按钮不选chooseIt(i);}}
}function getSum() {var temp = 0;var oSum = document.getElementById("priceTotal");var aItems = document.getElementsByClassName("check-one");var aSubtotal = document.getElementsByClassName("subtotal");//循环,计算选中的商品的总价格for (var j = 0; j < aItems.length; j++) {if (aItems[j].checked) {temp += parseInt(aSubtotal[j].innerText);} else {temp += 0;}}oSum.innerText = temp;
}function getGoods() {var num = 0;var oGoods = document.getElementById("selectedTotal");var aItems = document.getElementsByClassName("check-one");var aCountInput = document.getElementsByClassName("count-input");//循环,计算选中的商品的总数量for (var i = 0; i < aItems.length; i++) {if (aItems[i].checked) {num += parseInt(aCountInput[i].value);} else {num += 0;}}oGoods.innerText = num;
}function getTotal(n) {var aPrice = document.getElementsByClassName("price");var aCountInput = document.getElementsByClassName("count-input");var aSubtotal = document.getElementsByClassName("subtotal");//计算单件商品的总价var oMoney = parseInt(aPrice[n].innerText) * parseInt(aCountInput[n].value);aSubtotal[n].innerText = oMoney;
}function getPlus(n) {var aCountInput = document.getElementsByClassName("count-input");//增加单件商品的数量var temp = parseInt(aCountInput[n].value) + 1;aCountInput[n].value = temp;
}function getReduce(n) {var aCountInput = document.getElementsByClassName("count-input");//减少单件商品的数量var temp = parseInt(aCountInput[n].value) - 1;aCountInput[n].value = temp;//当剪到数量为1件时,停止减if (aCountInput[n].value < 1) {aCountInput[n].value = 1;}
}function showTotal() {var money = document.getElementById("priceTotal").innerText;alert("你总共花了" + money + "money");
}function chooseIt(i) {var aAdd = document.getElementsByClassName("add");var aReduce = document.getElementsByClassName("reduce")var aDel = document.getElementsByClassName("delete");var oTab = document.getElementById("cartTable");aAdd[i].onclick = function() {getPlus(i); //增加单件商品数量getTotal(i); //计算单间商品总价getSum(); //计算总商品价格getGoods(); //计算总商品数量}aReduce[i].onclick = function() {getReduce(i); //减少单件商品数量getTotal(i);getSum();getGoods();}aDel[i].onclick = function() {var oDialog = confirm("确定要删除吗?");if (oDialog) {oTab.tBodies[0].removeChild(aDel[i].parentNode.parentNode);getGoods();getSum();}getStart(); //更新表格中行的数量}getGoods(); //显示初始总商品数量(在勾选了该商品,但未增加数量时,显示默认数量1)getSum(); //显示初始商品总价(在勾选了该商品,但未增加数量时,显示默认总价为1件商品的金额)
}

1.3CSS代码

* {margin: 0;padding: 0;
}
a {color: #666;text-decoration: none;
}
body {padding: 20px;color: #666;
}
.fl{float: left;
}
.fr {float: right;
}
table {border-collapse: collapse;border-spacing: 0;border: 0;text-align: center;width: 1400px;
}
th, td {border: 1px solid #CADEFF;
}
th {background: #e2f2ff;border-top: 3px solid #a7cbff;height: 30px;
}
td {padding: 10px;color: #444;
}
tbody tr:hover {background: RGB(238,246,255);
}
.checkbox {width: 60px;
}
.goods {width: 80px;/* background-color: red; */text-align: center;
}
.sm {width: 120px;/* background-color: red; */text-align: center;
}
.sj {width: 150px;/* background-color: red; */text-align: center;
}
.goods img{margin-left: 70px;width: 80px;/* border: #A7CBFF 2px solid; */display: inline-block;/* float: left; */text-align:center;
}
.goods span {display: block;width: 80px;margin-top: 20px;text-align: center;margin-left: 70px;/* float: left; */
}
.price {width: 80px;
}
.count {width: 90px;
}
.count .add, .count input, .count .reduce {float: left;margin-right: -1px;position: relative;z-index: 0;
}
.count .add, .count .reduce {height: 23px;width: 17px;border: 1px solid #e5e5e5;background: #f0f0f0;text-align: center;line-height: 23px;color: #444;
}
.count .add:hover, .count .reduce:hover {color: #f50;z-index: 3;border-color: #f60;cursor: pointer;
}
.count input {width: 50px;height: 15px;line-height: 15px;border: 1px solid #aaa;color: #343434;text-align: center;padding: 4px 0;background-color: #fff;z-index: 2;
}
.subtotal {width: 80px;color: red;font-weight: bold;
}
.operation {width: 80px;
}
.operation span:hover, a:hover {cursor: pointer;color: red;text-decoration: underline;
}
img {width: 100px;height: 80px;/*border: 1px solid #ccc;*/margin-right: 10px;float: left;
}.foot {width: 1400px;margin-top: 10px;color: #666;height: 48px;border: 1px solid #c8c8c8;background-color: #eaeaea;background-image:linear-gradient(RGB(241,241,241),RGB(226,226,226));position: relative;z-index: 8;
}
.foot div, .foot a {line-height: 48px;height: 48px;
}
.foot .select-all {width: 100px;height: 48px;line-height: 48px;padding-left: 5px;color: #666;
}
.foot .closing {border-left: 1px solid #c8c8c8;width: 100px;text-align: center;color: #000;font-weight: bold;background: RGB(238,238,238);cursor: pointer;
}
.foot .total{margin: 0 20px;cursor: pointer;
}
.foot  #priceTotal, .foot #selectedTotal {color: red;font-family: "Microsoft Yahei";font-weight: bold;
}
.foot .selected {cursor: pointer;
}
.foot .selected .arrow {position: relative;top:-3px;margin-left: 3px;
}
.foot .selected .down {position: relative;top:3px;display: none;
}
.show .selected .down {display: inline;
}
.show .selected .up {display: none;
}
.foot .selected:hover .arrow {color: red;
}
.foot .selected-view {width: 935px;border: 1px solid #c8c8c8;position: absolute;height: auto;background: #ffffff;z-index: 9;bottom: 48px;left: -1px;display:none;
}
.show .selected-view {display: block;
}
.foot .selected-view div{height: auto;
}
.foot .selected-view .arrow {font-size: 16px;line-height: 100%;color:#c8c8c8;position: absolute;right: 330px;bottom: -9px;
}
.foot .selected-view .arrow span {color: #ffffff;position: absolute;left: 0px;bottom: 1px;
}
#selectedViewList {padding: 20px;margin-bottom: -20px;
}
#selectedViewList div{display: inline-block;position: relative;width: 100px;height: 80px;border: 1px solid #ccc;margin: 10px;
}
#selectedViewList div span {display: none;color: #ffffff;font-size: 12px;position: absolute;top: 0px;right: 0px;width: 60px;height: 18px;line-height: 18px;text-align: center;background: RGBA(0,0,0,.5);cursor: pointer;
}
#selectedViewList div:hover span {display: block;
}

二、效果图

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_905202.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

1 如何制定详尽的SEO计划

SEO&#xff08;Search Engine Optimization&#xff09;搜索引擎优化(网络营销):站内SEO和站外SEO 在网站上线前&#xff0c;SEO是必不可少的一个重点&#xff0c;但很多网站都没有详细的规划过如何开始动手做SEO&#xff0c;其实不管是大网站也好&#xff0c;小网站也罢&…

2 SEO关键词和长尾关键词的分析!

————————————————————————————————————————————— ————————————————————————————————————————————— —————————————————————————————————————…

如何判断网站是否被恶意镜像呢?

佛山SEO教你一个最简单的方法&#xff1a; 1、在电脑左下脚&#xff0c;点开始&#xff0c;点运行&#xff0c;在运行右边的框中输入cmd&#xff0c;进入命令模式 2、输入ping 自己的域名&#xff0c;回车 3、再输入ping 对方的域名&#xff0c;回车 4、比较一下两个域名所返…

3 站外SEO操作要点

1 网站提交给搜索引擎 2 网站的收录情况查询 3 站外锚文本 4 外链查询 5 PR值查询

网络推广人员需要掌握的SEO十大查询工具

网络推广人员SEO一定要做到"知己知彼"。知己&#xff0c;就是深入了解自己网站的推广情况&#xff1b;知彼&#xff0c;就是充分了解竞争对手网站的推广情况。网站推广情况是可以通过一些相关数据体现出来的。石家庄婚庆认为网络推广人员如果能够掌握以下十大SEO查询…

建立网站基本操作

首先想要建立自己的网站&#xff0c;就需要一个可以连通外网的服务器。 为什么建立网站需要购买服务器呢&#xff0c;服务器是一种高性能计算机。说的通俗一点&#xff0c;用户浏览网页&#xff0c;其实都是浏览的这台计算机里的网页文件&#xff0c;所以这是你想拥有一个任何…

让wordpress网站拥有以图搜图,智能搜图、图像搜索系统imgso,让网站更智能专业

专业素材网站的搜图功能&#xff1a; 很多背景墙、墙纸、壁纸、电视墙、装修设计素材网都必配以图搜图。这个以图搜图识图的好处不言而喻&#xff0c;是很多素材网、图片网、三维网等等必备功能。 推荐一款专业的以图搜图系统imgso&#xff0c;它是一个以图搜图专业系统&#x…

快速搭建类似千图、昵图的设计素材网站,素材交易网站源码下载

截止年底全球设计素材交易超过990亿美金&#xff0c;其中73%的素材来自欧洲地区&#xff0c;预计今年全球素材的交易将超过1000亿美金。中国是素材潜力国&#xff0c;市场巨大。全球9600万设计师&#xff0c;中国约有1700万设计大军。 设计师盈利渠道两种&#xff1a; 一种是辛…

大型高性能网站的十项规则

在我们公司ChinaNetCloud&#xff0c;见 过多种不同类型的网站和系统&#xff0c;有好也有差。其中有些系统拥有良好的服务器/网络架构&#xff0c;并且进行了合理的调整和监控 &#xff1b;然而一般的系统都会有安全和性能上的 问题&#xff0c;不能良好运行&#xff0c;也无法…

十二个最好的Icon资源网站

之前总结过不少Icon资源站点&#xff0c;不过有一些目前貌似已经不能访问&#xff0c;另外最近在爱库网上发现了很多不错的Icon资源站点&#xff0c;所以在这里重新整理了12个Icon资源站点&#xff0c;和大家分享。1.FindIcons.com就是一个帮您找免费图标的图标搜索引擎。有300…

Firefox Developer Edition已阻止此网站安装未经验证的附加组件的解决办法

about:config 中 xpinstall.signatures.required 设置为false. 以上。

阿里云+Ubuntu+LAMP+WordPress搭建个人博客网站

首发于个人网站http://139.196.86.184&#xff08;域名备案中&#xff09;&#xff0c;转载注明作者与出处&#xff0c;谢谢。 搭个人网站一般有两种选择&#xff1a; GitHub Pages Hexo / jekyl服务器 WordPress / Typecho 之前试过1&#xff0c;现在试试2&#xff0c;个…

火狐浏览器打开Web页面后出现:“此网站可能不支持TLS1.2协议,而这是Firefox支持的最低版本。”

火狐浏览器打开某厂商设备Web管理登录地址出现&#xff1a;“此网站可能不支持TLS1.2协议&#xff0c;而这是Firefox支持的最低版本。” 问题描述 火狐浏览器版本&#xff1a;“97.0.1 (64 位)”&#xff0c;打开某厂商设备Web管理地址时出现&#xff1a;“此网站可能不支持T…

rutracker网站无法进入,解决方案来啦

亲测过并解决了的我专门来提醒一下大家&#xff1a; edge和chrome我试过装了照样失败&#xff0c;和科学上网一点关系都没有。 火狐装完秒成功&#xff0c;甚至不用人机验证 直接进入 用到的2样东西 浏览器&#xff1a;FireFox国际版&#xff08;火狐浏览器 国际版&#xff…

为何搜索引擎跟电商网站那么懂我们的需求,一切都是“Cookie”在作祟!

不知道大家有没有注意过&#xff0c;当你在某搜索引擎搜索一些关键字时&#xff0c;列如“饮食健康”在你搜索并浏览过后&#xff0c;再次打开其他网站或者收到一些推广时&#xff0c;就会有“饮食健康”这类的信息&#xff0c;在电商网站时也是这样。出现这种现象当然不是你的…

使用Revel(go)开发网站

Revel很好的利用了Go语言的goroutine&#xff0c;把每一个request都分配到了goroutine里。不用再写一大堆的回调。如果你写过nodejs的话就会深刻的体会到callback hell是什么样子的。正是由于Revel有了goroutine&#xff0c;Revel的性能也有了很大的提升。官网号称请求的吞吐量…

jQuery中API网站结合post上传文件到阿里云OSS记录

文章目录 前景提示代码块HTML代码块javascript代码块string数据File对象FormDataEntryValue数组API测试使用的网站 代码块html代码块 javascript代码块执行结果 测试过程中遇到的问题总说缺少content参数但data里面有了原因解决解决之后传送的数据区分下processData参数在jQuer…

影视节前端网站,,以前东拼西凑的,前端课程设计应该可以吧.

介绍 很久以前为了应付课程设计的作业…在线演示 https://video-show.netlify.app/ 下载地址 github:https://github.com/superBiuBiuMan/film_videoShow_websitegitee:https://gitee.com/superBiuBiu/film_videoShow_website 图片展示 主页 影片展示 优秀演员 获奖名单 奖…

在线听音乐网站真是越来越多

以前在线听歌听音乐的网站总是躲躲藏藏&#xff0c;稍一有名&#xff0c;很快就不能听了。想必是因为版权的缘故。 不过最近发觉如雨后春笋&#xff0c;纷纷冒了出来。 有一阵子听1ting.com&#xff0c;不过也知道像sohu&#xff0c;sina都有&#xff0c;最近知道一个haoting…

.net三层结构建站之始

很多初学.net 的人&#xff0c;搞懂了三层结构的大概&#xff0c;在创建文件夹时却总不得法&#xff0c;主要是对.net 的使用不熟。我也一样&#xff0c;一样是个.net的新手&#xff0c;很久前就用三层结构做东西了&#xff0c;开始的时候就知道老师叫怎么建就怎么建&#xff0…