<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
div{
width: 640px;
margin: 0;
text-align: center;
margin-top:150px ;
}
#number{
display: inline-block;
width: 520px;
height: 36px;
font: 36px/36px arial;
text-align: center;
vertical-align: center;
border: none;
outline: none;
border-bottom: 1px solid darkgray;
float: left;
}
#check,#clear{
width: 120px;
height: 36px;
border: none;
outline: none;
background-color: peru;
}
</style>
</head>
<body>
<div id="search">
<input type="text" id="number" placeholder="请输入车牌号">
</div>
<button id="check" onclick="checkCarNo()">查看是否限行</button>
<button id="clear" onclick="clean()">清除历史纪录</button>
<hr >
<p id="result"></p>
<script type="text/javascript">
function checkCarNo(){
// 获取值
var input = document.getElementById('number');
var carno = input.value;
// 返回结果
var p = document.getElementById('result');
// 比对车牌号是否合法
var regex = /^[川云贵鲁][A-Z]\s*[0-9A-Z]{5}$/;
if (regex.test(carno)){
// 取出最后一位数字,查询是否限行
var day = new Date().getDay();
var digit = lastDigitStr(carno);
if (digit % 5 == day || digit % 5 == day -5){
p.innerHTML = carno + '今日限行<br>' + p.innerHTML ;
}else{
p.innerHTML = carno + '今日不限行<br>' + p.innerHTML;
}
}else{
p.innerHTML = carno + '无效,请输入有效车牌号码<br>'+p.innerHTML;
}
}
function lastDigitStr(str){
for(var index = str.length - 1; index >= 0;index -= 1){
var digitStr = str[index];
if(digitStr >= '0' && digitStr <= '9'){
return digitStr
} else{
return null
}}
}
function clean(){
document.getElementById('result').innerHTML=''
}
</script>
</body>
</html>
网友评论