购物车页面

main
pqjepwfgk 5 months ago
parent 0a9f7e45a6
commit 91d6b2321d

@ -0,0 +1,138 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>购物车</title>
<link rel="stylesheet" href="css/stylesheets.css" />
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<style>
/* body{
background-color: #e5e5e5;
} */
.top{
z-index: 999;
border-style: solid;
border-width: 1px;
border-color: #555;
height: 80px;
width: 100%;
position: fixed;
top: 0;
left: 0;
background-color: #1AA093;
text-align: center;
}
p{
font-size: 25px;
color: #e5e5e5;
}
</style>
</head>
<body onload="showItems();">
<div class="top">
<nav class="topText"><p>Arknights</p></nav>
<nav class="log"><a href="Login.html"><p >登录</p></a></nav>
<nav class="sign"><a href="#"><p>注册</p></a></nav>
</div>
<div class="seach">
<nav class="logo"></nav>
<ul class = "searchNav">
<li><a href="index.html"><p>首页</p></a></li>
<li><a href=""><p>推荐</p></a></li>
<li><a href=""><p>购物车</p></a></li>
<li><a href=""><p>个人信息</p></a></li>
</ul>
<nav class = "find">
<input type="text" name="seach" class = "my-input">
<button onclick="findBooks()" class = "findbooks"><p>查找</p></button>
</nav>
</div>
<div class = "mainBody">
<p>这是一行字</p>
<div id="001" class="item"><p>001</p><button class="min" onclick="delItem(0)"><p>-</p></button></div>
<div id="002" class="item"><p>002</p><button class="min" onclick="delItem(1)"><p>-</p></button></div>
<div id="003" class="item"><p>003</p><button class="min" onclick="delItem(2)"><p>-</p></button></div>
<div id="004" class="item"><p>004</p><button class="min" onclick="delItem(3)"><p>-</p></button></div>
<div id="005" class="item"><p>005</p><button class="min" onclick="delItem(4)"><p>-</p></button></div>
<div id="006" class="item"><p>006</p><button class="min" onclick="delItem(5)"><p>-</p></button></div>
<div id="007" class="item"><p>007</p><button class="min" onclick="delItem(6)"><p>-</p></button></div>
<div id="008" class="item"><p>008</p><button class="min" onclick="delItem(7)"><p>-</p></button></div>
<div id="009" class="item"><p>009</p><button class="min" onclick="delItem(8)"><p>-</p></button></div>
<div id="010" class="item"><p>010</p><button class="min" onclick="delItem(9)"><p>-</p></button></div>
<div id="011" class="item"><p>011</p><button class="min" onclick="delItem(10)"><p>-</p></button></div>
<div id="012" class="item"><p>012</p><button class="min" onclick="delItem(11)"><p>-</p></button></div>
</div>
<!-- <footer>
<p>版权所有,侵权必究</p>
</footer> -->
</body>
<script>
let name;
function findBooks(){
name = document.querySelector('.my-input').value;
$.getJSON("js/Info.json",function(data){
for(i in data.Title){
if(data.Title[i].includes(name,0)){
console.log(data.Title[i]);
console.log(data.Price[i]);
console.log(data.Picture[i]);
}
}
})
}
function showItems(){
let items = document.querySelectorAll('.item');
$.getJSON("js/cart.json",function(data){
for(let i=0;i<items.length;i++){
if(data.num[i]>0){
items[i].style.display = "block";
}else{
items[i].style.display = "none";
}
}
})
}
function delItem(n){
$.ajax({
type: 'POST',
dataType: 'text',
data: {
num : n
},
url: "js/test.php",
success: function(response){
showItems();
alert("已成功删除");
}
});
// $.getJSON("js/cart.json",function(data){
// data.num[n] = 0;
// for(let i=0;i<items.length;i++){
// if(data.num[i]>0){
// items[i].style.display = "block";
// }else{
// items[i].style.display = "none";
// }
// }
// });
}
// $.ajax({
// url: 'updateJson.php', // 后端处理修改 JSON 的 API 地址
// type: 'POST',
// data: { key: 'new value' }, // 要修改的数据
// success: function(response) {
// console.log('JSON 文件已成功更新');
// },
// error: function(error) {
// console.error('更新 JSON 文件时出错');
// }
// });
</script>
</html>
Loading…
Cancel
Save