HTML5驗證以及日期顯示的實現(xiàn)詳解

字號:


    以前忽略了HTML5的強大功能,誰知有了它數(shù)據(jù)大部分都不需要自己驗證,顯示日歷也不需要插件啦,一些小功能分享給大家
    1.Email輸入框,自動驗證Email有效性。
    代碼如下:
    <!DOCTYPE HTML>
    <html>
    <body>
    <form action="#" method="get">
    E-mail: <input type="email" name="user_email"/>
    <input type="submit"/>
    </form>
    </body>
    </html>
    2.number數(shù)字輸入,驗證正確,可以設(shè)置開始結(jié)束位。
    代碼如下:
    <!DOCTYPE HTML>
    <html>
    <body>
    <form action="#" method="get">
    <input type="number" step="5" min="5"max="20" name="number" value="0"/>
    <input type="submit"/>
    </form>
    </body>
    </html>
    3.URL輸入框,可以驗證URL輸入的有效性。
    <form action="#" method="get"> URL: <input type="url" name="user_email"/><br /> <input type="submit"/></form>
    4.Date pickers (date, month, week, time, datetime, datetime-local)選擇框,可以選擇日期,時間,月,周。
    代碼如下:
    <!DOCTYPE HTML>
    <html>
    <body>
    <form action="#" method="get">
    Date: <input type="date" name="user_email"/>
    month : <input type="month" name="user_email"/>
    week: <input type="week" name="user_email"/>
    time: <input type="time" name="user_email"/>
    datetime: <input type="datetime" name="user_email"/>
    datetime-local : <input type="datetime-local" name="user_email"/>
    <input type="submit"/>
    </form>
    </body>
    </html>
    5.datalist輸入選擇。
    代碼如下:
    <!DOCTYPE HTML> <html>
    <body>
    <form action="#" method="get">
    Webpage: <input type="url" list="url_list"value="fdf" name="user_email"/>
    <datalist id="url_list">
    <option label="W3School"value="http://www.w3school.com.cn"/>
    <option label="Microsoft" value="http://www.microsoft.com"/>
    </datalist><input type="submit"/>
    </form>
    </body>
    </html>