关于maxlength的使用
type 屬性規(guī)定 input 元素的類型。Type類型大致可分為文本輸入框,數(shù)字輸入框、密碼輸入框,單選/復(fù)選框,提交/重置按鈕等。下面介紹input中maxlength的使用。
1,type=text
參數(shù)name:同樣是表示的該文本輸入框名稱。
參數(shù)size:輸入框的長(zhǎng)度大小。
參數(shù)maxlength:輸入框中允許輸入字符的最大數(shù)。?
參數(shù)value:輸入框中的默認(rèn)值
特殊參數(shù)readonly:表示該框中只能顯示,不能添加修改。
<form>
your name:
<input type="text" name="yourname" size="30" maxlength="20" value="輸入框的長(zhǎng)度為30,允許最大字符數(shù)為20"><br>
<input type="text" name="yourname" size="30" maxlength="20" readonly value="你只能讀不能修改">
</form>
2,type=password
不用我說,一看就明白的密碼輸入框,最大的區(qū)別就是當(dāng)在此輸入框輸入信息時(shí)顯示為保密字符。
參數(shù)和“type=text”相類似。
<form>
your password:
<input type="password" name="yourpwd" size="20" maxlength="15" value="123456">密碼長(zhǎng)度小于15
</form>
3,type=file
當(dāng)你在BBS上傳圖片,在EMAIL中上傳附件時(shí)一定少不了的東西:)
提供了一個(gè)文件目錄輸入的平臺(tái),參數(shù)有name,size。
<form>
your file:
<input type="file" name="yourfile" size="30">
</form>
4,type=hidden
非常值得注意的一個(gè),通常稱為隱藏域:如果一個(gè)非常重要的信息需要被提交到下一頁,但又不能或者無法明示的時(shí)候。
一句話,你在頁面中是看不到hidden在哪里。最有用的是hidden的值。
<form name="form1">
your hidden info here:
<input type="hidden" name="yourhiddeninfo" value="cnbruce.com">
</form>
<script>
alert("隱藏域的值是 "+document.form1.yourhiddeninfo.value)
</script>
5,type=button
標(biāo)準(zhǔn)的一windows風(fēng)格的按鈕,當(dāng)然要讓按鈕跳轉(zhuǎn)到某個(gè)頁面上還需要加入寫JavaScript代碼
<form name="form1">
your button:
<input type="button" name="yourhiddeninfo" value="Go,Go,Go!" οnclick="window.open('http://www.cnbruce.com')">
</form>
6,type=checkbox
多選框,常見于注冊(cè)時(shí)選擇愛好、性格、等信息。參數(shù)有name,value及特別參數(shù)checked(表示默認(rèn)選擇)
其實(shí)最重要的還是value值,提交到處理頁的也就是value。(附:name值可以不一樣,但不推薦。)
<form name="form1">
a:<input type="checkbox" name="checkit" value="a" checked><br>
b:<input type="checkbox" name="checkit" value="b"><br>
c:<input type="checkbox" name="checkit" value="c"><br>
</form>
name值可以不一樣,但不推薦<br>
<form name="form1">
a:<input type="checkbox" name="checkit1" value="a" checked><br>
b:<input type="checkbox" name="checkit2" value="b"><br>
c:<input type="checkbox" name="checkit3" value="c"><br>
</form>
7,type=radio
即單選框,出現(xiàn)在多選一的頁面設(shè)定中。參數(shù)同樣有name,value及特別參數(shù)checked.
不同于checkbox的是,name值一定要相同,否則就不能多選一。當(dāng)然提交到處理頁的也還是value值。
<form name="form1">
a:<input type="radio" name="checkit" value="a" checked><br>
b:<input type="radio" name="checkit" value="b"><br>
c:<input type="radio" name="checkit" value="c"><br>
</form>
下面是name值不同的一個(gè)例子,就不能實(shí)現(xiàn)多選一的效果了<br>
<form name="form1">
a:<input type="radio" name="checkit1" value="a" checked><br>
b:<input type="radio" name="checkit2" value="b"><br>
c:<input type="radio" name="checkit3" value="c"><br>
</form>
8,type=image
比較另類的一個(gè),自己看看效果吧,可以作為提交式圖片
<form name="form1" action="xxx.asp">
your Imgsubmit:
<input type="image" src="../blog/images/face4.gif">
</form>
9,type=submit and type=reset
分別是“提交”和“重置”兩按鈕
submit主要功能是將Form中所有內(nèi)容進(jìn)行提交action頁處理,reset則起個(gè)快速清空所有填寫內(nèi)容的功能。
<form name="form1" action="xxx.asp">
<input type="text" name="yourname">
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>
10,type=number
<form name="form" action="">?
<input type="number" οninput="if(value.length>5)value=value.slice(0,5)" />
</form>
總結(jié)
以上是生活随笔為你收集整理的关于maxlength的使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 对象哈希码
- 下一篇: 银行自助设备详细介绍(三)——取款机