1. 車牌限行判斷
html:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>work01-車牌</title>
<style>
</style>
</head>
<body>
<div id="limit">
請輸入車牌號:
<select class="province">
</select>
<input type="text" id="license" value="">
<input id="submit" type="button" value="確定">
<p id="result"></p>
</div>
<script>
</script>
</body>
</html>
css:
* {
margin: 0;
padding: 0;
}
body {
width: 80%;
margin: 0 auto;
font-size: 18px;
}
#limit {
text-align: center;
position: relative;
top: 100px;
}
.province {
font-size: 14px;
}
#license {
position: relative;
height: 18px;
font-size: 18px;
font-family: 'Courier New', Courier, monospace;
}
#submit {
height: 18px;
font-size: 18px;
}
#result {
margin-top: 50px;
margin-left: -50px;
position: relative;
font-size: 20px;
font-family: 'Times New Roman', Times, serif;
}
js:
(function () {
let province = document.querySelector('.province')
let license = document.querySelector('#license')
let result = document.querySelector('#result')
let sBtn = document.querySelector('#submit')
function fixSelect() {
//生成省份選擇下拉列表
const proList = '京、滬各谚、津霜旧、渝场航、魯射亏、冀琢唾、晉寡壮、蒙生闲、遼、吉掀泳、黑雪隧、蘇、浙开伏、皖膀跌、閩、贛固灵、豫捅伤、湘、鄂巫玻、粵丛忆、桂祠汇、瓊、川熄诡、貴可很、云、藏凰浮、陜我抠、甘、青袜茧、寧菜拓、新、港笛厦、澳纳鼎、臺'.split('、')
fixStr = '<option value="">--選擇省份--</option>'
for (let i = 0; i < proList.length; i += 1) {
fixStr += `<option value="${proList[i]}">${proList[i]}</option>`
}
province.innerHTML = fixStr
}
function testNum(str) {
// 驗(yàn)證車牌
let matchRule =
/^(([京津滬渝冀豫云遼黑湘皖魯新蘇浙贛鄂桂甘晉蒙陜吉閩貴粵青藏川寧瓊使領(lǐng)][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津滬渝冀豫云遼黑湘皖魯新蘇浙贛鄂桂甘晉蒙陜吉閩貴粵青藏川寧瓊使領(lǐng)][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9掛學(xué)警港澳使領(lǐng)]))$/
if (!matchRule.test(str)) {
return false
} else {
return true
}
}
function getLastNum(str) {
// 選擇字符串最后一位數(shù)字
for (let i = str.length - 1; i > -1; i -= 1) {
num = parseInt(str[i])
if (!isNaN(num)) {
return num
}
}
return null
}
function judgeLicense() {
// 判斷是否限行(成都)
if (!testNum(province.value + license.value)) {
alert('車牌號錯誤!')
province.value = ''
license.value = ''
result.textContent = ''
return
}
const rule = [
[1, 6],
[2, 7],
[3, 8],
[4, 9],
[5, 0]
]
let weekday = new Date().getDay()
// 可以出行/本日限行
if (weekday < 6) {
let carLastNum = getLastNum(license.value)
if (rule[weekday - 1].indexOf(carLastNum) !== -1) {
result.textContent = "本日限行"
} else {
result.textContent = "可以出行"
}
} else {
result.textContent = "可以出行"
}
}
license.addEventListener('keyup', function (e) {
if (e.keyCode == '13') {
judgeLicense()
}
})
sBtn.addEventListener('click', judgeLicense)
fixSelect()
})()
2. 點(diǎn)名系統(tǒng)
html:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>work02-點(diǎn)名</title>
<style>
</style>
</head>
<body>
<div id="main">
<h1>點(diǎn)名系統(tǒng)</h1>
<p id="student"></p>
<input id="start" type="button" value="開始">
<input id="reset" type="button" value="重新開始">
</div>
<script>
</script>
</body>
</html>
css:
*{
margin: 0;
padding: 0;
}
body{
width: 80%;
margin: 0 auto;
}
#main{
text-align: center;
position: relative;
top: 200px;
}
#student{
margin: 20px;
height: 44px;
font-size: 36px;
line-height: 44px;
}
input[type="button"]{
width: 100px;
height: 50px;
font-size: 20px;
line-height: 50px;
font-family:'Courier New', Courier, monospace;
background-color: gray;
position: relative;
}
#reset {
position: absolute;
top: 130px;
left: 330px;
visibility: hidden;
}
js:
(function () {
let stuList = [
'苗源', '王力', '高中軒', '楊斌'
]
// sessionStorage.setItem('stuList', JSON.stringify(stuList))
// stuList = JSON.parse(sessionStorage.getItem('stuList'))
let student = document.querySelector('#student')
let counter = 0
let tmpList = stuList.concat()
let interval = null
function getRandom() {
if (counter < 20) {
index = parseInt(Math.random() * stuList.length)
student.textContent = tmpList[index]
tmpList.splice(index, 1)
counter += 1
} else {
clearInterval(interval);
}
if (counter % stuList.length == 0) {
tmpList = stuList.concat()
console.log(counter)
}
}
function inter(){
if (counter < 20) {
index = parseInt(Math.random() * stuList.length)
student.textContent = tmpList[index]
tmpList.splice(index, 1)
counter += 1
} else {
clearInterval(interval);
student.textContent = tmpList[index]
}
if (counter % stuList.length == 0) {
tmpList = stuList.concat()
console.log(counter)
}
}
let stBtn = document.querySelector('#start')
let reBtn = document.querySelector('#reset')
stBtn.addEventListener('click', () => {
interval = setInterval(inter, 100)
reBtn.style.visibility = 'visible'
stBtn.style.visibility = 'hidden'
})
reBtn.addEventListener('click', () => {
counter = 0
interval = setInterval(inter, 100)
})
})()
3.列表刪除頁面
html:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>work03-列表刪除</title>
<style>
</style>
</head>
<body>
<div id="main">
<ul class="list"></ul>
<div class="bottom">
<input type="text" id="text">
<input id="submit" type="button" value="確定">
</div>
</div>
<script>
</script>
</body>
</html>
css:
* {
margin: 0;
padding: 0;
/* border: 1px solid salmon; */
}
body {
width: 80%;
height: 500px;
margin: 0 auto;
}
#main {
position: relative;
margin: 0 auto;
text-align: center;
}
.list {
/* margin-top: 100px; */
list-style: none;
color: white;
font-size: 28px;
}
.list>li {
width: 200px;
height: 50px;
line-height: 50px;
margin: 0 auto;
position: relative;
background-color: rgb(79, 141, 143);
border-bottom: 1px solid white;
}
li>a {
text-decoration: none;
position: absolute;
top: 5px;
right: 2px;
}
li>a:link,
li>a:visited {
color: white;
font-size: 20px;
line-height: 40px;
}
.bottom {
position: relative;
margin: 0 auto;
text-align: center;
overflow: hidden;
}
#text {
display: inline-block;
position: relative;
left: 65px;
width: 200px;
height: 50px;
border: none;
border-bottom: 1px solid darkgray;
outline: none;
text-align: center;
font-size: 18px;
margin: 0 auto;
}
#submit {
display: inline-block;
position: relative;
left: 65px;
bottom: -10px;
width: 120px;
height: 30px;
background-color: rgb(252, 106, 63);
color: white;
border: none;
outline: none;
cursor: pointer;
}
js:
(function () {
let fruitList = ['蘋果', '香蕉', '火龍果', '西瓜']
let ulList = document.querySelector('.list')
let fruit = document.querySelector('#text')
let btn = document.querySelector('#submit')
let index = 0
function drawList() {
// 生成初始列表
str = ''
for (index; index < fruitList.length; index += 1) {
str +=
`<li id="l_${index}">${fruitList[index]}<a href="javascript:void(0);" onclick="delFruit('l_${index}');">x</a></li>`
}
ulList.innerHTML = str
}
delFruit = function (id) {
// 刪除列表項
let li = document.getElementById(id)
li.remove()
}
function addFruit() {
str =
`<li id="l_${index}">${fruit.value}<a href="javascript:void(0);" onclick="delFruit('l_${index}');">x</a></li>`
ulList.insertAdjacentHTML('beforeEnd', str)
index += 1
}
fruit.addEventListener('keyup',
function (e) {
if (e.keyCode == '13') {
addFruit()
}
})
btn.addEventListener('click', addFruit)
drawList()
})()
4. 購物車頁面
html:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>work04-購物車</title>
<style>
</style>
</head>
<body>
<div class="main">
<form action="" method="post">
<div class="header">
<div class="left">
<input type="checkbox" id="allCheckbox">全選
<span>商品</span>
</div>
<div class="right">
<span>單價</span>
<span>數(shù)量</span>
<span>小計</span>
<span>操作</span>
</div>
</div>
<div class="row">
<div class="line">
<div><input type="checkbox" name="myId" value=""></div>
<div>
<img src="" width="70" height="80">
<span>海瀾之家/Helain Home</span>
</div>
</div>
<div class="row_right">
<div>100元</div>
<div class="num">
<span class="sub">-</span>
<span><input type="text" class="val" value="x"></span>
<span class="sum">+</span>
</div>
<div class="price">100元</div>
<div>
<a href="">刪除</a>
</div>
</div>
</div>
<div class="center_bottom">
<a href="" class="delete">刪除選中產(chǎn)品</a>
<span>共選中了<font id="allnum">0
</font>件商品 總計: ¥<font id="allpri">0</font>元</span>
<span><button>去結(jié)算</button></span>
</div>
</form>
</div>
</body>
</html>
css:
* {
margin: 0;
padding: 0;
/* border: 1px solid salmon; */
}
a {
text-decoration: none;
}
a:link,
a:visited {
color: black;
}
body {
width: 960px;
height: 700px;
margin: 0 auto;
position: relative;
}
.main {
width: 80%;
height: 500px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.header {
overflow: hidden;
height: 40px;
line-height: 40px;
background-color: #EEEEEE;
border-bottom: 1px solid #ccc
}
.header .left {
float: left;
}
.header .left span {
margin-left: 70px;
}
.header .right {
float: right;
}
.header .right:last-child {
margin-right: 0px
}
.header div,
.header span {
font-size: 14px;
margin-right: 70px
}
.row {
height: 85px;
border-bottom: 1px solid gray;
line-height: 85px;
padding-bottom: 10px;
}
.row>div {
margin-right: 28px;
}
.line div {
float: left;
}
.line div>img {
margin-left: 10px;
}
.line div>span {
display: block;
float: right;
width: 200px;
height: 85px;
line-height: 85px;
text-align: center;
bottom: 30px;
}
.row>div div {
float: left;
}
.line:first-child {
margin-top: 30px
}
.row_right {
float: right;
}
.row_right div {
width: 105px;
text-align: center;
}
.sub,
.sum {
cursor: pointer;
font-size: 16px;
}
.val {
width: 20px;
text-align: center;
}
.center_bottom {
clear: both;
width: 500px;
position: relative;
text-align: right;
}
.center_bottom>a{
float: left;
color: gray;
}
.center_bottom:first-child{
float: left;
width: 250px;
height: 40px;
margin-right: 100px;
}
.center_bottom font {
color: red;
font-size: 20px
}
.center_bottom button {
float: right;
margin-right: -250px;
background-color: red;
color: white;
width: 90px;
height: 30px;
font-size: 16px;
border: none;
outline: none;
}