HTML標籤之——<input>

<input>是HTML衆多標籤中最豪華的標籤,擁有30多種屬性,最常見的應用是在<form>標籤中
常用的type以及屬性
屬性:
     type                 input的類型(或則說輸入域的顯示形式)
     maxlength       最多輸入夫人字符數
     size                  輸入域的長度(測試不好用)
     value               輸入域的值
     placeholder     默認提示
     readonly         只讀
     patten            輸入驗證的正則
     checked         (複選框或則單選框)以及被選中
     disabled         input框無法獲得焦點
     tabindex        輸入域TAB的遍歷順序
     name             非常非常重要  
type:
     text             ----文本框
     password     ----密碼
     checkbox     ----複選框
     radio            ----單選框
     submit         ----提交
     image          ----圖片(表單中點擊可以用來提交表單)
     file               ----選擇文件選項
     hidden         ----隱藏(網頁中不可見,但是表單提交的時候還是會被提交)
     reset            ----重置
     button         ----按鈕    
1.type = "text" input標籤中最常見的一種(包含placeholder,tabindex,maxlength,list用法)
<input type="text" mame ="apple" maxlength="10" placeholder = "請輸入" list ="listdata">
<datalist id="listdata">
      <option laber="en">red</option>
      <option>yollow</option>
</datalist>



type="text"                input框中可以輸入文本
maxlength="10"        只能輸入10個字符,多餘10的將不顯示
list ="listdata"            配合<datalist>標籤,構建input框的下拉選擇和提示,自動補全(H5新增的比較不錯的一個屬性,只用於text屬性)
<datalist>                  <datalist>中是構建選擇(提示的內容),<option>還可以使用laber屬性爲option提供說明



2.type ="password" 密碼輸入

<input type="password"  placeholder = "請輸入密碼qqqqqqqqqqqqqq" name="" maxlength="10" 


這個大家登陸註冊什麼的時候都有用到,都很熟
   額外加了maxlength  和list(正常的輸入密碼的input框是用不到的)
   只爲說明placeholder不受type類型 和maxlength影響



 3.submit  reset  button
這三個一起講的原因是它們最後生成的都是按鈕的樣式
 
 <form>
       <input type="text" mame ="apple" maxlength="10" placeholder = "請輸入" list ="listdata">
        <datalist id="listdata">
            <option label="en">red</option>
            <option>yollow</option>
        </datalist>
        <p>
        <input type="password"  placeholder = "請輸入密碼" name="pwd"   >
        <p>
        <input type="submit" name="" value="提交" formaction="http://www.baidu.com" formmethod="POST" >
        <input type="reset" name="" value="重置內">
        <input type = "button" value = "按鈕">
    </form>
        <input type="reset" name="" value="重置外">
 
這邊需要說明幾點
(1)submit是用來提交的,在type=“submit”之後還可以使用formaction formmethod formtarge                                              formnovalidate分別重寫form表單中的action method  target novalidate屬性 
(2)type=“reset”只能在表單中重置表單內容,在表單外沒有作用
(3)type = “button“生成的只是普通按鈕



4.type = “hidden”

 <input type="hidden" name="name" value = "1">
這個在頁面上說明也看不到,但是有一點非常重要:就是在表單提交的時候hidden的內容也會被提交(可以用來把藥提交的數據放置在表單的hidden input框中,提交的時候一起提交到後臺服務器)



5.type =“checkbox”

複選框:<input type="checkbox" name="vigg" checked >

(1)給複選框框設置checked屬性就會默認選中
(2)複選框在沒有勾選提交表單的時候不會提交,只有在被勾選的時候纔會被提交(默認爲on)



6.type = “radio”

 單選框:<input type="radio" name="select">apple
       <input type="radio" name="select" checked >orange
       <input type="radio" name="select">yellow


單選框和複選框的用法差不多,暫不多說

7.type = “date”

<input type="date" name="time">


用在需要用戶輸入日期的時候,效果不錯;

8.type =“color”

 <input type="color" name="color">


點擊能顯示出一個顏色選擇器,雖然用到的地方不多,但是效果還是不錯的

9.type =“file”

  <input type="file" name="file" multiple >



這是一個讓人有愛有恨的功能,它很好解決了PC端上傳文件到服務器,但是可恨的是在移動端,蘋果手機支持還可以,Android在這方面就是個大坑啊,之前做過一個在微信端需要上傳的功能,各種Android支持不一同,有的打不開文件選擇,有的不支持multiple多選屬性,最後只能用微信自己的接口(js-sdk)實現

10.type = “image” + 分區響應

<input type="image" src="xxxxxxxxxxxx" height="xxxxxxx" formaction = "xxx" formmethod="xxx" ... >
image的用法和submit有點像,就是多了src和height屬性,其他formeacton 屬性用法都一樣
但是image還有一個特性,點擊image的時候不止會提交表單信息,還會提交點擊相對於圖片左上角的座標位置,這樣就可以來做分區響應了,點擊不同區域進行不同的操作。


11.number range
這兩個都是針對數字的

<input type="number" name="number" min="0" max="100" step="5" >
<input type="range" name="a" min="0" max="100" step="1" >

min max是設置最小最大的,step是設置步長的



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章