input對象
input對象
一個<input>標記,就是一個input對象。
input對象的屬性(以type=text為例)
name:表單元素的名稱。
value:表單元素的值,用戶輸入的內(nèi)容,可以通過該屬性來獲取。
size:表單的長度。
maxlength:表單元素的最大長度(最多可輸?shù)淖址麛?shù))。
disabled:禁用屬性。
readonly:只讀屬性。
input對象的方法
focus():獲得焦點的方法(定位光標)。
blur():失去焦點的方法(移走光標)。
select():選中文本的方法。
input對象的事件
onfocus:當獲得焦點時
onblur:當失去焦點時
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> </script> </head> <body> <form name="form1" method="post" action="login.php"> 用戶名:<input type="text" name="username" onfocus="this.value='focus';this.select()" onblur="this.value='blur'" /> 密碼:<input type="password" name="userpwd" /> <input type="submit" value="提交表單" /> </form> </body> </html>