<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<title>Test</title>
</head>
<style>
.container {
display: flex;
flex-wrap: nowrap;
justify-content: space-around;
}
.goods-list {
margin: 50px auto;
display: flex;
flex-wrap: wrap;
width: 500px;
height: 300px;
border: 1px solid black;
opacity: 0;
}
.goods-list h1 {
margin: 0 10px;
}
.shop-cart {
position: absolute;
bottom: 0;
right: 0;
padding: 20px 100px;
border: 1px solid black;
}
</style>
<script type="text/javascript">
var xhr;
var isIE=false;
var isShopCart=false;
function getXMLHttpRequest() {
if (window.XMLHttpRequest) {
if (navigator.userAgent.indexOf('MSIE') != -1) {
isIE = true;
}
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
function init() {
xhr = getXMLHttpRequest();
if(xhr) {
xhr.onreadystatechange = handleResponse;
} else {
alert("你的浏览器不支持ajax!推荐使用firefox或者chrome浏览器访问!");
}
}
function addGoods(id) {
if(xhr) {
xhr.open("POST", "/addGood");
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send('商品' + id);
}
}
function loadGoods() {
if(xhr) {
xhr.open("GET", "/loadGoods");
xhr.send();
}
console.log('获取商品')
}
function handleResponse() {
if(xhr.readyState == 4) {
if(xhr.status == 200 || xhr.status == 304) {
if (isShopCart) {
var goods = JSON.parse(xhr.responseText).message
$(".goods-list").empty();
for (let i = 0; i < goods.length; i++) {
$(".goods-list").append(`<h1>${goods[i]}</h1>`)
}
} else {
alert('提交成功')
}
}
}
}
</script>
<body onload="init()">
<div class="container">
<div class="good-content">
<h1>商品1</h1>
<button id="#btn1" onclick="addGoods(1)">添加</button>
</div>
<div class="good-content">
<h1>商品2</h1>
<button onclick="addGoods(2)">添加</button>
</div>
<div class="good-content">
<h1>商品3</h1>
<button onclick="addGoods(3)">添加</button>
</div>
<div class="good-content">
<h1>商品4</h1>
<button onclick="addGoods(4)">添加</button>
</div>
<div class="good-content">
<h1>商品5</h1>
<button onclick="addGoods(5)">添加</button>
</div>
</div>
<div class="goods-list">
</div>
<div class="shop-cart">
购物车
</div>
</body>
<script>
$(document).ready(function(){
$(".shop-cart").mouseenter(function () {
loadGoods()
isShopCart = true;
$(".goods-list").css("opacity", "1")
})
$(".shop-cart").mouseleave(function () {
$(".goods-list").css("opacity", "0")
isShopCart = false;
})
});
</script>
</html>

帮窝消消黑眼圈
- 粉丝: 72
最新资源
- 计算机在现代测绘技术的应用.docx
- 互联网科技IT产品宣传介绍PPT模板ppt模板.pptx
- 分解因式与互联网搜索教案设计方案.doc
- 项目管理培训及应用感受分析.docx
- office计算机二级办公软件考试-office高级应用技术元文档.doc
- 人大金仓KingbaseES企业数据库中的两种垂直分区技术详解.doc
- GIS实用技术的洪水淹没模拟及灾害评估.doc
- 新型网络技术对教师继续教育培训行业的影响.docx
- 滨海新区智慧城市建设与发展研究.doc
- 机械设计制造及其自动化专业人才培养研究与实践.docx
- 学生宿舍管理系统数据库课程研究设计doc.doc
- 论计算机网络安全与防火墙技术.docx
- 基于网络的土工虚拟仿真试验室开发.docx
- 深度学习下小学语文习作单元活动设计与思考.docx
- 运用信息化手段进行科学课导入的方法例谈.docx
- hplc体内药物分析实用技术.ppt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


