Input标签中Type的类型及详细⽤法
Input表⽰Form表单中的⼀种输⼊对象,其⼜随Type类型的不同⽽分⽂本输⼊框,密码输⼊框,单选/复选框,提交/重置按钮等,下⾯⼀⼀介绍。
1,type=text
输⼊类型是text,这是我们见的最多也是使⽤最多的,⽐如登陆输⼊⽤户名,注册输⼊电话号码,电⼦邮件,家庭住址等等。当然这也是Input的默认类型。参数name:同样是表⽰的该⽂本输⼊框名称。
参数size:输⼊框的长度⼤⼩。
参数maxlength:输⼊框中允许输⼊字符的最⼤数。
参数value:输⼊框中的默认值
特殊参数readonly:表⽰该框中只能显⽰,不能添加修改。
<form>
your name:
<input type="text" name="yourname" size="30" maxlength="20" value="输⼊框的长度为30,允许最⼤字符数为20"><br>
<input type="text" name="yourname" size="30" maxlength="20" readonly value="你只能读不能修改">
</form>
2,type=password
不⽤我说,⼀看就明⽩的密码输⼊框,最⼤的区别就是当在此输⼊框输⼊信息时显⽰为保密字符。
参数和“type=text”相类似。
<form>
your password:
<input type="password" name="yourpwd" size="20" maxlength="15" value="123456">密码长度⼩于15
</form>
3,type=file
当你在BBS上传图⽚,在EMAIL中上传附件时⼀定少不了的东西:)
提供了⼀个⽂件⽬录输⼊的平台,参数有name,size。
<form>
your file:
<input type="file" name="yourfile" size="30">
</form>
4,type=hidden
⾮常值得注意的⼀个,通常称为隐藏域:如果⼀个⾮常重要的信息需要被提交到下⼀页,但⼜不能或者⽆法明⽰的时候。
⼀句话,你在页⾯中是看不到hidden在哪⾥。最有⽤的是hidden的值。
<form name="form1">
your hidden info here:
<input type="hidden" name="yourhiddeninfo" value="cnbruce">
</form>
<script>
alert("隐藏域的值是 "+urhiddeninfo.value)
</script>
5,type=button
标准的⼀windows风格的按钮,当然要让按钮跳转到某个页⾯上还需要加⼊写JavaScript代码
<form name="form1">
your button:
<input type="button" name="yourhiddeninfo" value="Go,Go,Go!" onclick="window.open('')">
</form>
6,type=checkbox
多选框,常见于注册时选择爱好、性格、等信息。参数有name,value及特别参数checked(表⽰默认选择)
其实最重要的还是value值,提交到处理页的也就是value。(附:name值可以不⼀样,但不推荐。)inputtypefile不上传文件
<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
即单选框,出现在多选⼀的页⾯设定中。参数同样有name,value及特别参数checked.
不同于checkbox的是,name值⼀定要相同,否则就不能多选⼀。当然提交到处理页的也还是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值不同的⼀个例⼦,就不能实现多选⼀的效果了<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
⽐较另类的⼀个,⾃⼰看看效果吧,可以作为提交式图⽚
<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中所有内容进⾏提交action页处理,reset则起个快速清空所有填写内容的功能。<form name="form1" action="xxx.asp">
<input type="text" name="yourname">
<input type="submit" value="提交">
<input type="reset" value="重置">
</form>