html5中表單新增元素與屬性

來源:互聯網
上載者:User

標籤:伺服器   tar   lis   datalist   val   表單   需要   pattern   png   

form

很多初學者對與form不是很理解,其實從html的MDN中可以看出,form是用在前背景互動上的,比如我需要把表單的內容(input裡的內容提交到後台),這是就需要input包裹在form裡面。

1 <form action="xxx.php" method="post">2     <input type="text" name="ID">3     <input type="submit" name="submit">4 </form>

form屬性中action就是表單要提交到的地方,method是提交的方法(有get和post兩種)。

 

特別介紹的屬性:

1.formaction:就是form和action的結合。上面的代碼可以看到action是表單提交到的伺服器(後台),但是在html5之前,一個form表單內部只能提交到同一個伺服器,而formaction可以設定input元素提交到不同的伺服器,就象這樣:

<form  method="post">        <input type="submit" name="submit" formaction="1.php">    <input type="submit" name="submit" formaction="2.jsp">    <input type="submit" name="submit" formaction="3.asp"></form>

而類似的formenctype,formmethod和formtarget都是可以針對不同的表單內部的元素進行的操作。而具體的enctype,method和target參見網上的教程。

 

2.placeholder:就是為文字框設定一個簡短的提示資訊。

1 <input type="text" name="submit" placeholder="請輸入你的學號">

3.list:為文字框添加一個下來菜單選項(包含預定義的選項)。

1 <form  >2     <input list="datalist1">3     <datalist id="datalist1">4     <option value="1"></option>5     <option value="2"></option>6     <option value="3"></option>7     <option value="4"></option>8     </datalist>9 </form>

4.pattern:用於驗證Regex。

 

 

後記:關於form表單還有部分新增的屬性在這裡沒有介紹,主要是因為這些屬性還不能在大部分瀏覽器上使用或者流行,如果有興趣可以自己瞭解。

 

 

html5中表單新增元素與屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.