<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
rel="stylesheet"
href="./css/common.css" />
<link
rel="stylesheet"
href="./css/task.css" />
<script src="./js/flexible.js"></script>
</head>
<body>
<!-- 1. header1头部公共区域 -->
<div class="header1">
<a
class="father"
data-id="0">
待提货
<p class="line"></p>
</a>
<a
class="father"
data-id="1">
在途
<p class="line"></p>
</a>
<a
class="father"
data-id="2">
已完成
<p class="line"></p>
</a>
</div>
<!-- 3. 主体区域 -->
<div class="container">
</div>
<!-- 2. footer底部公共区域 -->
<div class="footer">
<a href="javascript:;"
><img
src="./assests/first.png"
alt="" />
<p>任务</p></a
>
<a href="javascript:;"
><img
src="./assests/second.png"
alt="" />
<p>消息</p></a
>
<a href="javascript:;"
><img
src="./assests/last.png"
alt="" />
<p>我的</p></a
>
</div>
<script>
let indexArr = []
const info = [
{
num: 'XAHH1234567',
from: '北京市昌平区回龙观街道西三旗桥东金燕龙写字楼 8877 号',
to: '河南省郑州市路北区北清路 99 号',
time: '2022.05.04 13:00:00',
},
{
num: 'YBHJ1234567',
from: '上海市浦东新区世纪大道 123 号金贸大厦 1234 室',
to: '广东省深圳市南山区科技中一路 99 号',
time: '2022.05.05 14:00:00',
},
{
num: 'ZXCS1234567',
from: '杭州市西湖区文一西路 123 号中关村科技大厦 8877 室',
to: '江苏省南京市江北新区江北大道 99 号',
time: '2022.05.06 15:00:00',
},
{
num: 'ABCD1234567',
from: '成都市青羊区蜀都大道 123 号环球中心 1234 室',
to: '重庆市江北区观音桥街道建新东路 99 号',
time: '2022.05.07 16:00:00',
},
{
num: 'EFGH1234567',
from: '天津市滨海新区泰达街道第四大街 123 号滨海金融大厦 1234 室',
to: '河北省石家庄市鹿泉区北站街 99 号',
time: '2022.05.08 17:00:00',
},
]
const header1 = document.querySelector('.header1')
const lines = document.querySelectorAll('.line')
header1.addEventListener('touchstart', function (e) {
if ((e.target.tagName = 'DIV')) {
let num = e.target.dataset.id
lines.forEach(function (item) {
item.style.width = '0px'
item.parentNode.style.color = '#818181'
})
lines[num].style.width = '23px'
e.target.style.color = '#2a2929'
}
})
const container = document.querySelector('.container')
setContainer()
function setContainer() {
const arr = info.map(function (item) {
return `
<div class="task">
<a class="title" href="./detail.html">
<p>任务编号: ${item.num}</p>
<span>已延迟</span>
</a>
<a class="main" href="./detail.html">
<div class="address">
<p class="from">起</p>
<div class="sline"></div>
<p class="to">止</p>
</div>
<div class="right">
<p class="from">${item.from}</p>
<p class="to">${item.to}</p>
</div>
</a>
<div class="bottom">
<div class="bleft">
<p>提货时间</p>
<p class="time">${item.time}</p>
</div>
<div class="bright">提货</div>
</div>
</div>
`
})
container.innerHTML = arr.join('')
const brights = document.querySelectorAll('.bright')
brights.forEach(function (item, index) {
item.addEventListener('touchstart', function () {
this.style.backgroundColor = '#FADCD9'
})
})
const titles = document.querySelectorAll('.title')
const mains = document.querySelectorAll('.main')
titles.forEach(function(item,index){
item.addEventListener('touchstart',function(e){e.preventDefault()
localStorage.setItem('detail',JSON.stringify(info[index]))
})
})
}
</script>
</body>
</html>
/* 去除常见标签默认的 margin 和 padding */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 设置网页统一的字体大小、行高、字体系列相关属性 */
body {
font: 16px/1.5 "Microsoft Yahei", "Hiragino Sans GB", "Heiti SC", "WenQuanYi Micro Hei", sans-serif;
background-color: #F4F4F4;
}
/* 去除列表默认样式 */
ul,
ol {
list-style: none;
}
/* 去除默认的倾斜效果 */
em,
i {
font-style: normal;
}
/* 去除a标签默认下划线,并设置默认文字颜色 */
a {
text-decoration: none;
color: #333;
}
/* 设置img的垂直对齐方式为居中对齐,去除img默认下间隙 */
img {
width: 100%;
height: 100%;
vertical-align: middle;
}
/* 去除input默认样式 */
input {
border: none;
outline: none;
color: #333;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: 400;
}
/* 清除浮动 */
.clearfix::before,
.clearfix::after {
content: '';
display: block;
}
.clearfix::after {
clear: both;
}
.container {
width: 9.49333333rem;
margin: 0 auto;
}
.header1 {
padding: 0 0.82666667rem;
width: 100%;
height: 1.33333333rem;
background-color: #fff;
display: flex;
align-items: center;
position: fixed;
left: 0;
top: 0;
}
.header1 .father {
font-size: 0.42666667rem;
margin-right: 0.96rem;
color: #818181;
position: relative;
white-space: nowrap;
}
.header1 .father:first-child {
color: #2a2929;
}
.header1 .father:first-child .line {
width: 0.61333333rem;
}
.header1 .father .line {
width: 0;
height: 0.10666667rem;
background-color: #ef4f3f;
position: absolute;
bottom: -0.16rem;
left: 50%;
transform: translateX(-50%);
border-radius: 0.05333333rem;
transition: all 0.3s;
}
body {
padding: 1.33333333rem 0.4rem 0;
}
body .container {
width: 100%;
height: 100%;
margin-bottom: 1.73333333rem;
}
body .container .task {
display: block;
width: 9.2rem;
height: 6.10666667rem;
margin: 0.4rem 0;
padding: 0.4rem 0.34666667rem 0 0.50666667rem;
border-radius: 0.26666667rem;
background-color: #fff;
}
body .container .task .title {
display: flex;
justify-content: space-between;
align-items: center;
}
body .container .task .title p {
font-size: 0.42666667rem;
color: #2a2929;
}
body .container .task .title span {
display: none;
font-size: 0.32rem;
border: 0.02666667rem solid #ef4f3f;
width: 1.38666667rem;
height: 0.58666667rem;
color: #ef4f3f;
border-radius: 0.29333333rem;
text-align: center;
line-height: 0.53333333rem;
}
body .container .task .main {
display: flex;
margin: 0.58666667rem 0;
}
body .container .task .main .address {
display: flex;
flex-direction: column;
height: 1.97333333rem;
width: 0.58666667rem;
justify-content: space-between;
}
body .container .task .main .address .sline {
flex: 1;
width: 0.02666667rem;
border: 0.02666667rem dashed #eee;
margin: 0 auto;
}
body .container .task .main .address p {
color: #fff;
text-align: center;
line-height: 0.58666667rem;
font-size: 0.32rem;
border-radius: 50%;
width: 0.58666667rem;
height: 0.58666667rem;
}
body .container .task .main .address p:nth-child(1) {
background-color: #2a2929;
}
body .container .task .main .address p:last-child {
background-color: #ef4f3f;
}
body .container .task .main .right {
margin-left: 0.29333333rem;
flex: 1;
}
body .container .task .main .right p {
font-size: 0.37333333rem;
color: #818181;
}
body .container .task .main .right p:nth-child(1) {
margin-bottom: 0.29333333rem;
}
body .container .task .bottom {
padding-top: 0.37333333rem;
border-top: 0.02666667rem solid #eee;
display: flex;
justify-content: space-between;
align-items: center;
}
body .container .task .bottom .bleft p {
font-size: 0.37333333rem;
}
body .container .task .bottom .bleft p:first-child {
color: #818181;
}
body .container .task .bottom .bleft p:last-child {
color: #2a2929;
}
body .container .task .bottom .bright {
width: 2.13333333rem;
height: 0.85333333rem;
border-radius: 0.42666667rem;
background-color: #ef4f3f;
font-size: 0.42666667rem;
color: #fff;
text-align: center;
line-height: 0.85333333rem;
}
/*
p{
&.acitve
}
双选加类选择器
*/
/*
p{
& .active
}
子代选择器 .active
*/
具体js代码和css基础样式下面有,要实现的效果就是点击提货按钮后即使再次刷新页面,提货按钮样式也是保持上次点击后的样子,即下面这样:
1.点击前
2.点击后
我原来想的是通过本地存储点击过的不同的提货按钮编号来找到这个按钮,然后再它被点击之后重新渲染页面,再通过这个编号index来单独设置它的样式已经放在渲染函数里面了,在二次渲染的后面,结果发现只有二次渲染执行了,更改的样式并没有被执行,请教下怎么解决这两个问题:
1.实现提货按钮按下后再次刷新也能保持禁用状态不变
2.怎么样可以让用户只能点击一次提货按钮且刷新后保持不能按下按钮触发?