HTML5表單,html5表單一實例

來源:互聯網
上載者:User

HTML5表單,html5表單一實例

HTML5中添加了表單方面的諸多功能,包括增加input輸入類型、表單元素、form屬性和input屬性等。

一.新增的Input輸入類型:

     email:      <input type="email" name="user_email" />

     url:           <input type="url" name="user_url" />

     number:  <input type="number" name="user_number"  min="1" max="20" step="4" />   max:規定允許的最大值;min:規定允許的最小值;step:規定合法的數字間隔(如果step="4",則合法的數是-4、0、4、8);value:規定預設值

    range:     <input type="range" name="user_range"min="1" max="20" step="4" />

    日期類型: date、month、week、time、datetime、datetime-local

    search:   <input type="search" name="user_search" />

    tel:           <input type="tel" name="user_tel" />

    color:      <input type="color" name="user_color" />

二.新增的input屬性:

    autocomplete:  協助使用者在input類型的輸入框中實現自動完成內容輸入,這些Input類型包括:text、search、url、telephone、email、password、datepickers、range和color;該屬性值有3種:on、off和空值

    autofocus:         擷取頁面表單控制項焦點,同一個頁面只能使用一個autofocus屬性值;設定on即擷取焦點
                              <input type="text" name="user_name" autofocus="on" />

    list:                    HTML5中新增了一個datalist元素,可以實現資料列表的下拉效果,外觀類似autocomplete,使用者可從列表中選擇,也可自行輸入。而list屬性用於指定輸入框所綁定的datalist元素,其值是某個datalist的id         

請輸入城市<input type="text" list="<span style="color:#ff0000;">text_list</span>" name="weblink" /><datalist id="<span style="color:#ff0000;">text_list</span>">   <option value="BeiJing">BeiJing</option>   <option value="QingDao">QingDao</option>   <option value="QingHai">QingHai</option></datalist>
  list屬性適用於以下Input輸入類型:text、search、url、telephone、Email、date pickers、number、range、color

   min、max、step:  新增的min、max、step屬性用於為包含數字或日期的Input輸入類型規定限制,也就是給這些類型的輸入框加一個數值的約束,適用於date、pickers、number和range標籤。

   multiple:該屬性支援input輸入類型中的file類型一次選擇多個檔案 

 <input type="file" name="img" multiple="multiple" /><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">   </span>

  patterm:  用於驗證Input類型輸入框中使用者輸入的內容是否與自訂的Regex相匹配,適用於以下類型的Input標籤:text、search、url、telephone、Email、password。
  請輸入郵遞區號:  <input type="text" name="zip_code" pattern="[0-9]{6}"/>    該行表示輸入框規定必須輸入6位元的郵遞區號

   placeholder:用於為Input類型的輸入框提供一種提示。適用於:text、search、url、telephone、Email和password
    請輸入郵遞區號:  <input type="text" name="zip_code" pattern="[0-9]{6}"/>    

   required:  內容不可為空 。適用於:text、search、url、telephone、Email、password、date pickers、number、checkbox、radio和file
   <input type="text" name="n_name" required="required"/>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.