You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.7 KiB
124 lines
3.7 KiB
<!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>
|
|
<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"><p>-</p></button></div>
|
|
<div id="003" class="item"><p>003</p><button class="min"><p>-</p></button></div>
|
|
<div id="004" class="item"><p>004</p><button class="min"><p>-</p></button></div>
|
|
<div id="005" class="item"><p>005</p><button class="min"><p>-</p></button></div>
|
|
<div id="006" class="item"><p>006</p><button class="min"><p>-</p></button></div>
|
|
<div id="007" class="item"><p>007</p><button class="min"><p>-</p></button></div>
|
|
<div id="008" class="item"><p>008</p><button class="min"><p>-</p></button></div>
|
|
<div id="009" class="item"><p>009</p><button class="min"><p>-</p></button></div>
|
|
<div id="010" class="item"><p>010</p><button class="min"><p>-</p></button></div>
|
|
<div id="011" class="item"><p>011</p><button class="min"><p>-</p></button></div>
|
|
<div id="012" class="item"><p>012</p><button class="min"><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]);
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
let items = document.querySelectorAll('.item');
|
|
$.getJSON("js/cart.json",function(data){
|
|
data.num[0] = 1;
|
|
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){
|
|
$.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> |