DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML5教程
HTML5 表單與文件學習筆記
編輯:HTML5教程     

一、新增元素與屬性

form 屬性:指定所屬表單,讓表單內的控件可以寫在表單之外的任意位置。

<form id="testform">
  <input type="text">
</form>
<textarea form="testform"></textarea>

formaction 屬性:點擊不同按鈕時,可把表單提交到不同頁面。

<form id="textform" action="sever.jsp">
  <input type="submit" name="s1" value="v1" formaction="s1.jsp">提交到s1
  <input type="submit" name="s2" value="v2" formaction="s2.jsp">提交到s2
  <input type="submit" name="s3" value="v3" formaction="s3.jsp">提交到s3
  <input type="submit">
</form>

formmethod 屬性:指定提交方法。

<form id="teatform" action="serve.jsp">
  <input type="submit" name="s1" value="v1" formaction="s1.jsp" formmethod="post">提交到s1
  <input type="submit" name="s2" value="v2" formaction="s2.jsp" formmethod="get">提交到s2
  <input type="submit">
</form>

placeholder 屬性:顯示輸入提示。

<input type="text" placeholder="input me">

autofocus 屬性:頁面加載後自動獲得焦點。

<input type="text" autofocus>

list 屬性:獲得焦點後以提示列表的方式顯示候選值。

text:<input type="text" name="greeting" list="greetings">
<datalist id="greetings" style="display:none;">
  <option value="Good Morning">Good Morning</option>
  <option value="Hello">Hello</option>
  <option value="Good Afternoon">Good Afternoon</option>
</datalist>

autocomplete 屬性:自動顯示候補數據。

<input type="text" name="greeting" autocomplete="on" list="greeting">

二、input 元素的新類型

url 類型:專門用來輸入 URL 地址的文本框。

<input name="url" type="url" value="https://www.microsoft.com">

email 類型:專門用來輸入 email 地址的文本框。

<input type="email" name="email" value="llingma2005@yahoo.com.cn">

date 類型:以日曆形式方便輸入日期。

<input type="date" name="date1" value="2010-10-02">

time 類型:專門用來輸入時間。

<input type="time" name="time1" value="10:00">

datetime 類型:用來輸入 UTC 時間,提交時自動進行有效性檢查。

<input type="datetime" name="datetime1">

datetime-local 類型:用來輸入本地時間。

<input type="datetime-local" name="datetime-local1">

month 類型:用來輸入月份。

<input type="month" name="month1" value="2010-10">

week 類型:用來輸入周號。

<input type="week" name="week1" value="2010-w40">

number 類型:用來輸入數字,可搭配 min、max、step 限制範圍與步長。

<input type="number" name="number1" value="25" min="10" max="100" step="5">

range 類型:以滑桿形式在範圍內取值。

<input type="range" name="range1" value="25" min="10" max="100" step="5">

search 類型:專門輸入搜尋關鍵詞。

input[type="search"] {-webkit-appearance:textfield;}

tel 類型:專門輸入電話號碼。

color 類型:專門用來選取顏色。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved