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) {
// 验证车牌
let matchRule =
/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/
if (!matchRule.test(str)) {
return false
} else {
return true
}
}
function getLastNum(str) {
// 选择字符串最后一位数字
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. 点名系统
html:
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>work02-点名</title>
<style>
</style>
</head>
<body>
<div id="main">
<h1>点名系统</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>数量</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">删除选中产品</a>
<span>共选中了<font id="allnum">0
</font>件商品 总计: ¥<font id="allpri">0</font>元</span>
<span><button>去结算</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;
}