HTML5--新增和改良的input元素類型


image

將圖片從本地提交到服務(wù)器上。

<html>
    <head>
        <title>
         image demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <form action="">
        <!--將圖片從本地提交到服務(wù)器-->
        <input type="image" width="100%" height="100%" src="E:\前端學(xué)習(xí)\image\dog.jpg">
        </form>
    </body>
</html>

Url

輸入正確網(wǎng)址才能提交,否則不能提交。

<html>
    <head>
        <title>
         url demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <form>
        <!--輸入正確網(wǎng)址才能提交,否則不能提交-->
        <input type="url" name="url">
        <input type="submit" value="提交">
        </form>
    </body>
</html>

email

輸入正確郵箱地址才能提交,否則不能提交。

<html>
    <head>
        <title>
         email demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <form method="POST" action="http://localhost:5000/api/formtest/email">
        <!--輸入正確郵箱地址才能提交,否則不能提交-->
        <input type="email" name="email">
        <input type="submit" value="提交">
        </form>
    </body>
</html>

date、time、datetime、datetime-local、month、week

<html>
    <head>
        <title>
         date demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <!--date日期-->
        <input type="date">
        <!--time時(shí)間-->
        <input type="time">
        <!--datetime UTC時(shí)間-->
        <input type="datetime">
        <!--datetime-local 本地時(shí)間-->
        <input type="datetime-local">
        <!--month月-->
        <input type="month">
        <!--week周-->
        <input type="week">
    </body>
</html>

number

用于應(yīng)該包含數(shù)值的輸入域。

<html>
    <head>
        <title>
         number demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <input type="number" max="100" min="-10" value="10" step="5">number簡(jiǎn)用</number>
        <h1>乘法運(yùn)算</h1>
        <input type="number" id="num_one">
        <input type="number" id="num_two">
        <input type="number" id="result">
        <input type="button" value="計(jì)算" onclick="calculation()">
        <script>
        function calculation(){
            //valueAsNumber:轉(zhuǎn)換為數(shù)值類型
            var n1 = document.getElementById("num_one").valueAsNumber; 
            var n2 = document.getElementById("num_two").valueAsNumber;
            document.getElementById("result").valueAsNumber = n1 * n2;
        }
        </script>
    </body>
</html>

range與output

range:進(jìn)度條。output:輸出。以下示例為range與output混用。

<html>
    <head>
        <title>
        output demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <!--range:進(jìn)度條-->
        <input type="range" max="50" id="range" step="2" min="0" value="0" onchange="setter()">
        <!--output標(biāo)簽:定義不同類型的輸出,比如腳本的輸出-->
        <output id="output"></output>
        <script>
         function setter(){
            var range_value = document.getElementById("range").value;
            console.log(range_value);
            document.getElementById("output").value = range_value;
         }
        </script>
    </body>
</html>

color

系統(tǒng)顏色選擇器。

<html>
    <head>
        <title>
         color demo
        </title>
        <meta charset="UTF-8">
    </head>
    <body>
        <form>
            <input type="color" onchange="document.form.style.backgroundColor;">
            <input type="text" list="greetings">
            <datalist id="greetings">
                <option>文件一</option>
                <option>文件二</option>
            </datalist>
        </form>
    </body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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