除了基本的 <input>,HTML 尚提供 <textarea>(多行文字)、<select>(下拉/清單選單)、<fieldset>(群組框架)等進階控制項,滿足更豐富的資料輸入需求。
<form name="表單名" method="get|post" action="URL">
<textarea name="名稱" rows="行數" cols="字元寬度" [readonly]>預設文字</textarea>
</form>
| 屬性 | 說明 |
|---|---|
name | 控制項名稱,伺服器端 Request.Form("名稱") 取值 |
rows | 可見行數(高度) |
cols | 每行字元寬度(寬度) |
readonly | 唯讀,使用者不可編輯但仍可複製、提交 |
disabled | 停用,灰色不可互動,**不會隨表單提交** |
wrap | 自動換行模式:off (預設, 橫向捲軸) / soft / hard (提交時換行) |
預設值:置於 <textarea>...</textarea> 之間,可包含換行。
<html>
<head><title>多行文字輸入</title>
<style>body,td,th{font-size:11pt;color:#000;line-height:1.5} body{margin-top:50px}</style></head>
<body>
<form method="post" name="form1" action="8.asp">
<table align="center" bgcolor="#d6d3ce">
<tr><th bgcolor="#0099cc"><font color="#ffffff">多行文字輸入</font></th></tr>
<tr><td height="50" align="left"><font color="#000000">請您留言:</font></td></tr>
<tr><td height="50"><textarea name="內容" cols="50" rows="4">贈人玫瑰,手留餘香。</textarea></td></tr>
<tr align="center"><td height="50">
<input type="submit" value="提交" name="btnSubmit">
<input type="reset" value="重置" name="btnReset"></td></tr>
</table>
</form>
<p><p><center>**********************************************</center>
<%
Dim f1
f1 = Request.Form("內容")
If f1 <> "" Then
Response.Write "<center><b>您的留言為:" & f1 & "</b></center>"
Else
Response.Write "<center><b>您還沒有留言。</b></center>"
End If
%>
</body></html>
<form name="表單名" method="get|post" action="URL">
<select name="名稱" size="可見選項數" [multiple]>
<option [selected] value="值1">顯示文字1</option>
<option [selected] value="值2">顯示文字2</option>
...
</select>
</form>
| 屬性 | 說明 |
|---|---|
name | 控制項名稱 |
size | 可見選項數;size=1 為下拉選單,>1 為清單方塊 |
multiple | 允許多選 (Ctrl/Shift 點選);單選時省略 |
selectedIndex | 目前選取項索引 (0-based),可讀寫 |
length | 選項總數 (唯讀) |
style | CSS 樣式,如 width:100px;height:30px |
| 屬性 | 說明 |
|---|---|
value | 提交給伺服器的值;省略則用顯示文字 |
selected | 預設選中 (單選僅一個) |
text | 顯示文字 (唯讀,對應 innerText) |
<html>
<head><title>使用清單方塊</title>
<style>body,td,th{font-size:11pt;color:#000;line-height:1.5} body{margin-top:50px}</style></head>
<body>
<center><h3>使用清單方塊</h3><hr width="50%">
<select size="2" style="width:100px;" name="select1">
<option value="Bei jings">北京</option>
<option value="Shang hai">上海</option>
<option value="Tian jin">天津</option>
<option value="Chong qing">重慶</option>
</select><p>
清單選項個數:<input type="text" name="text1" size="3"></p>
選定項 Value:<input type="text" name="text2" size="10"></p>
選定項 Text:<input type="text" name="text3" size="10"></p></center>
<script for="select1" event="onClick" language="VBScript">
Dim i
i = select1.selectedIndex
text1.value = select1.length
text2.value = select1.options(i).value
text3.value = select1.options(i).text
</script>
</body></html>
說明:客戶端 VBScript (IE) 即時將選取項的索引、值、文字回填至三個文字框。
<form>
<fieldset>
<legend>個人基本資料</legend>
姓名:<input type="text" name="name"><br>
年齡:<input type="number" name="age">
</fieldset>
<fieldset>
<legend>聯絡方式</legend>
Email:<input type="email" name="email"><br>
電話:<input type="tel" name="phone">
</fieldset>
</form>
<legend> 提供群組標題,瀏覽器預設繪製圍框與標題嵌入框線。| 控制項 | 單選/多選 | Request.Form 回傳型態 | 處理方式 |
|---|---|---|---|
textarea | 單值 | 字串 (含換行) | 直接使用;顯示時 Replace(vbCrLf, "<br>") |
select (無 multiple) | 單選 | 字串 (value) | 直接使用 |
select (有 multiple) | 多選 | 逗號分隔字串 | Split(Request.Form("name"), ",") 或迴圈 .Count |
checkbox 群組 | 多選 | 逗號分隔字串 | 同 select multiple |
radio 群組 | 單選 | 字串 (value) | 直接使用 |
type="email", tel, url, number, date, color, range 等,瀏覽器內建驗證與鍵盤優化。<datalist> 搭配 <input list="..."> 實現自動完成下拉。<table> 佈局,語意化標籤 (<label>, <fieldset>) 提升無障礙分數。熟練運用 textarea、select、fieldset,能設計出結構清晰、使用者友善、伺服器端易處理的專業表單。