form
<form action=”http://www.github.com” onsubmit=”return false;”>
提交内容到网页
form独有onsubmit事件,当此事件触发时,表单数据被提交
submit按钮的作用是自动触犯表单onsubmit事件
事件可以取消:当return false时,当且仅当false时才取消,否则提交
input
1.表单元素:
只有在此元素之内输入的数据才能提交到服务器
2.表单控件: input元素:
1)文本框:
value:设置默认值;
maxlength:设置最大长度;
readonly:设置只读;
account:<input type=”text” value=”albertliang” maxlength=”10” readonly/>
2)密码框:
password:<input type=”password”/>
3)单选框:
checked:设置默认选中
name:组名;同一组radio互斥
Gender:
<input type=”radio” name=”gender”/>male
<input type=”radio” name=”gender”/>female
4)多选框:
checked:设置默认选中
Hobby:
<input type=”checkbox”/>delicious
<input type=”checkbox”/>social
<input type=”checkbox”/>compete
<input type=”checkbox”/ checked>reading
5)隐藏框: ###用来传递不希望被用户看到的数据,数据通过value属性进行默认的设置
<input type=”hidden” value=”love”/>
6)文件选择框
head:<input type=”file”/>
7)按钮(提交、重置、普通)
<input type=”submit” value=”sign in”/>
—form中的网址
<input type=”reset” value=”reset”/>
<input type=”button” value=”test”/>
3.其他元素
1)label:
用来管理表单中的文字,可以将文字与框绑定在一起,从而增加这个框的可点击面积,提高易用性
步骤:
a)给框增加id,用于唯一标识此框
b)在文字歪增加label标签,加属性for=”id”
<input type=”checkbox” id=”la”/>
—或radio
<label for=”la”>I have read and agree this degree!</label>
2)下拉选项:
selected:设置默认选中
City:
<option>Please choose</option>
<option>Shanghai</option>
<option>Shenzhen</option>
<option selected>Beijing</option>
<option>Chengdu</option>
3)文本域
cols:设置宽度;
rows:设置高度;
readonly:设置只读
Intro:
<textarea rows=”5” cols=”30”>type something here</textarea>