css样式:推荐采用flex或者grid布局
<style type="text/css">
*{
margin: 0;
padding: 0;
border: 0;
position: relative;
font-size: 16px;
}
#div01{
display: flex;
height: 500px;
width:500px;
flex-direction: column;
align-items: center;
background: lightblue;
margin: auto;
}
#div02{
display: flex;
width:480px;
display: flex;
justify-content: space-between;
}
#carno{
border:1px solid black;
width: 300px;
height: 30px;
margin: 20px 0;
vertical-align: middle;
}
#show{
height: 300px;
width: 480px;
/* text-align: start; */
}
#summit,#reload{
font-size: 20px;
font-family: "黑体";
border: 0 ;
cursor: pointer;
width: 60px;
height: 30px;
margin: 20px 0;
background-color:lightgreen;
color: rgb(115,115,115);
}
</style>
html代码:
<div id="div01">
<div id="div02">
<input type="text" name="" id="carno" placeholder="请输入车牌..."/>
<input type="button" id="summit" value="提交" onclick="calulate()"/>
<input type="button" name="" id="reload" value="重置" onclick="reloadtext()"/>
</div>
<textarea rows="" cols="" id="show">
</textarea>
</div>
JS代码:
<script type="text/javascript">
function lastdigit(str){
for (var index=str.length-1;index>=0;index-=1){
var digitStr=str[index];
if(digitStr>="0" && digitStr<="9"){
return digitStr;
}
}
return null;
}
function calulate(){
var carNo=document.getElementById("carno").value;
console.log(carNo);
var regex= /^[川云贵渝京津沪][A-Z](·|\s*)[0-9A-Z]{5}$/;
console.log(regex.test(carNo));
text_area=document.getElementById("show")
if (regex.test(carNo)){
var digitStr=lastdigit(carNo);
if(digitStr){
var digit=parseInt(digitStr);
var day = new Date().getDay();
if (day>0 && day<6 &&(digit%5==day||digit%5==day-5)){
text_area.value+="车牌:"+carNo+"今日限行\n";
}
else{
text_area.value+="车牌:"+carNo+"今日不限行\n";
}
}
else{
text_area.value+="车牌:"+carNo+"无效\n";
}
}
else{
text_area.value+="车牌:"+carNo+"无效\n";
}
}
function reloadtext(){
document.getElementById("carno").value=null;
document.getElementById("show").value=null;
window.location.reload();
}
</script>
效果:
Python彩蛋
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
优美胜于丑陋(代码格式、内容一目了然)
Explicit is better than implicit.
明了胜于晦涩(显示化、明确化、规范化的代码风格)
Simple is better than complex.
简洁胜于复杂(尽量不要使用嵌套)
Complex is better than complicated.
复杂胜于凌乱(如果无法避免复杂,一定不能凌乱,可以低耦合、高内聚)
Flat is better than nested.
扁平胜于嵌套(不能有太多的嵌套)
Sparse is better than dense.
稀疏优于密集(代码保持一定的松紧度,不能太紧凑)
Readability counts.
可读性很重要(见名知义、注释得体)
Special cases aren't special enough to break the rules.
特殊情况不足以打破规则(不能因为特例打破编码规则)
Although practicality beats purity.
实用性胜过纯洁(代码实用性更重要,算法复杂度越小越好)
Errors should never pass silently.
错误不应该默默地传递(不要放过代码中任何一个错误,代码保持高度的严谨性)
Unless explicitly silenced.
除非明确沉默
In the face of ambiguity, refuse the temptation to guess.
面对模棱两可,拒绝猜测的诱惑(不要猜测代码的执行结果)
There should be one-- and preferably only one --obvious way to do it.
应该有一个 - 最好只有一个 - 显而易见的方法。(用一个最好的显而易见的方法去解决问题)
Although that way may not be obvious at first unless you're Dutch.
虽然这种方式起初可能并不明显,除非你是荷兰人。(你不是Guido,所以代码的优美程度可能一开始不会太好)
Now is better than never.
不要拖延,现在开始永远比不做好
Although never is often better than right now.
做也许好过不做,但不假思索就动手还不如不做(动手之前要细思量)
If the implementation is hard to explain, it's a bad idea.
如果你无法向人描述你的方案,那肯定不是一个好方案
If the implementation is easy to explain, it may be a good idea.
如果实现很容易解释,那可能是个好主意。(优秀的方案应该简明扼要,通俗易懂)
Namespaces are one honking great idea -- let's do more of those!
命名空间是一个很棒的主意 - 让我们做更多的事情吧!(命名空间可以做到内外有别、避免冲突)