Day25--課后作業(yè)(車牌限行)

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+"今日限行\(zhòng)n";
                        }
                        else{
                            text_area.value+="車牌:"+carNo+"今日不限行\(zhòng)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>

效果:

微信截圖_20181105175606.png

Python彩蛋
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
優(yōu)美勝于丑陋(代碼格式、內(nèi)容一目了然)
Explicit is better than implicit.
明了勝于晦澀(顯示化、明確化、規(guī)范化的代碼風(fēng)格)
Simple is better than complex.
簡潔勝于復(fù)雜(盡量不要使用嵌套)
Complex is better than complicated.
復(fù)雜勝于凌亂(如果無法避免復(fù)雜,一定不能凌亂,可以低耦合、高內(nèi)聚)
Flat is better than nested.
扁平勝于嵌套(不能有太多的嵌套)
Sparse is better than dense.
稀疏優(yōu)于密集(代碼保持一定的松緊度,不能太緊湊)
Readability counts.
可讀性很重要(見名知義、注釋得體)
Special cases aren't special enough to break the rules.
特殊情況不足以打破規(guī)則(不能因為特例打破編碼規(guī)則)
Although practicality beats purity.
實用性勝過純潔(代碼實用性更重要,算法復(fù)雜度越小越好)
Errors should never pass silently.
錯誤不應(yīng)該默默地傳遞(不要放過代碼中任何一個錯誤,代碼保持高度的嚴(yán)謹(jǐn)性)
Unless explicitly silenced.
除非明確沉默
In the face of ambiguity, refuse the temptation to guess.
面對模棱兩可,拒絕猜測的誘惑(不要猜測代碼的執(zhí)行結(jié)果)
There should be one-- and preferably only one --obvious way to do it.
應(yīng)該有一個 - 最好只有一個 - 顯而易見的方法。(用一個最好的顯而易見的方法去解決問題)
Although that way may not be obvious at first unless you're Dutch.
雖然這種方式起初可能并不明顯,除非你是荷蘭人。(你不是Guido,所以代碼的優(yōu)美程度可能一開始不會太好)
Now is better than never.
不要拖延,現(xiàn)在開始永遠比不做好
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.
如果實現(xiàn)很容易解釋,那可能是個好主意。(優(yōu)秀的方案應(yīng)該簡明扼要,通俗易懂)
Namespaces are one honking great idea -- let's do more of those!
命名空間是一個很棒的主意 - 讓我們做更多的事情吧?。臻g可以做到內(nèi)外有別、避免沖突)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容