HTML表单

2017-04-27  本文已影响0人  锦雯书

表单就是手机用户信息的,让用户填写、选择的。

<div>

<h3>欢迎注册本网站</h3>

<form>所有的表单内容,都要写在form标签里</form>

</div>

注释:form是英语表单的意思,form标签里面有action属性和method属性,action属性指示表单将提交到哪里。method属性表示用什么HTTP方法提交,有get和post两种。

1、文本框

<input type="text"/>

input表示“输入”,指的是这是一个“输入小部件”,

type表示“类型”,

text表示“文本”,指的是类型是一个文本框的输入小部件。

这是一个自封闭标签。自此,认识过的自封闭标签有:

<meta name="Keywords" content=""/>

<img src="" alt=""/>

<input type="text">

vaule标示“值”,vaule属性就是默认有的值,文本框中已经被填写好了:<input type="text" vaule="默认的值"/>

2、密码框

<input type="password"/>

也就是说,input标签很神奇,既是文本框,又是密码框。

根据type的属性值来区分input标签到底是什么。

如果<type="text"/>则是文本框;

如果<type=“password”/>则是密码框。

3、单选按钮

只能选一个,术语叫“互斥”。

<input type="radio" name="xingbie"/>男

<input type="radio name="xingbie"/>女

radio是收音机的意思,input的type的值,如果是radio就是单选按钮。非常像以前的收音机,暗下去一个按钮,其他的就抬起来了,所以就叫radio。

单选按钮天生是不“互斥”的,如果想互斥,必须要有相同的name属性,name就是“名字”。

<input type="radio" name="xingbie"/>男

<input type="radio name="xingbie"/>女

默认被选择,就应该书写checked=“checked”

<input type="radio" name="sex" checked="checked">

4、复选框

也就是input标签,type是CheckBox。

<p>

请选择你的爱好:

<input type="checkbox" name="aihao"/>睡觉

<input type="checkbox" name="aihao"/>吃饭

<input type="checkbox" name="aihao"/>足球

<input type="checkbox" name="aihao"/>篮球

<input type="checkbox" name="aihao"/>乒乓球

<input type="checkbox" name="aihao"/>打豆豆

</p>

复选框最好也是有相同的name。(虽然他不需要互斥,但是也需要有相同的name)

5、下拉列表

select就是“选择”,option就是“选项”。

select标签和ul、ol、dl一样,都是组标签。

<select>

<option>北京</option>

<option>上海</option>

<option>广州</option>

<option>深圳</option>

</select>

6、多行文本框(文本域)

text就是文本,area就是区域。

<textarea cols="30" rows="10"></textarea>

这是个标签对儿,对儿里面不用写东西,如果写的话就是这个框的默认文字。

cols属性表示columns“列”,rows表示rows“行”。

值就是一个数,表示多少行,多少列。

7、三种按钮

-普通按钮:<input type="button" vaule="我是一个普通按钮"/>

button就是英语“按钮”的意思,vaule就是“值”的意思,即按钮上面显示的文字。

-提交按钮:<input type="submit"/>

submit就是英语“提交”的意思。这个按钮不用写vaule自动就有“提交”文字。这个按钮点击,表单就真的能提交,这个表单就会被提交到,form标签的action属性中的那个页面中去。

-重置按钮:<input type="reset"/>

reset就是“复位”的意思。

8、label标签

<input type="radio" name="sex"/>男

<input type="radio" name="sex"/>女

本质上讲,“男”、“女”这两个个汉字和input元素没有关系。

label就是解决这个问题的。

<input type="radio" name="sex" id="man"/><label for="man">男</label>

<input type="radio" name="sex" id="woman"/></label for="woman">女</label>

input元素要有一个id,然后label标签就要一个for属性,和id相同,就表示绑定了这个label和input之间的关系。

复选框也可以有label:<input type="checkbox" id="kk"/>

<input for="kk">10天内免登陆</label>

什么表单元素都有label。

上一篇 下一篇

猜你喜欢

热点阅读