DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML入門知識
9.4 單行文字框 text
編輯:HTML入門知識     

一、單行文字框 text 簡介

單行文字框是表單裡最常見的元件,登入、註冊、搜尋几乎都看得到它。

語法:

<input type="text"/>

舉例:

<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form name="form1" method="post" action="index.html">
姓名:<input type="text"/>
</form>
</body>
</html>

二、單行文字框的屬性

單行文字框 text 屬性
屬性說明
value定義文字框的預設值,也就是框內的初始文字
size定義文字框的長度,以字元為單位
maxlength限制最多可輸入的字元數

屬性順序不拘。input 另有 name 屬性,在 XHTML 中已被摒棄,因此只需掌握這三個。

<input type="text" value="預設文字" size="文字框長度" maxlength="最多輸入字元數"/>

舉例:

<!DOCTYPE html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form name="form1" method="post" action="index.html">
姓名:<input type="text" value="" size="15" maxlength=""/><br/>
年齡:<input type="text" value="18" size="3" maxlength="3"/>
</form>
</body>
</html>

分析:「年齡」那格預設值為 18,maxlength 設為 3,代表最多只能打三個字元——畢竟沒有人的歲數是四位數。你可以在線上測試工具裡試著多打幾個數字,瀏覽器會硬性擋住。

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