HTML5中form表单标签用途详解
语法: <form method = "传送方式" action = "效劳器文件">
讲解:1.<form>是成对显现的, 以<form> 开端, 以 </form>完毕,表单都必需放在其之间。
2.method 传送方式, get/post 是后端程序员思考的问题
3.action 阅读者输入的数据被传送到的地方,比方一个php页面, (save.php)
<form method="post" action="save.php">
<label for="username">会员名:</label>
<input type="text" name="username" />
<label for="pass">密码:</label>
<input type="password" name="pass" />
</form>
文本输入框,密码输入框
当会员需要在表单中键入字母,数据等,就要用到文本输入框,文本输入框也可以转化为密码输入框
语法:
<form>
<input type = "text/password" name = "名称" value = "文本" />
</form>
讲解:1.type :
当 type 为 text时,为文本输入框
当 type 为 password 时, 为密码输入框
2.name :为文本框命名,以备后台asp php使用
3.value :为文本输入框设定默许值(一样起提醒作用)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>文本输入框、密码输入框</title>
</head>
<body>
<form method="post" action="save.php">
账户:
<input type = "text" name = "myName" />
<br />
密码:
<input type = "password " name = "pass"/>
</form>
</body>
</html>
结果:
账户:
密码:
文本域:支撑多行文本输入
当会员需要在表单中输入大段文字时,就要用到文本输入域
语法:
<textarea rows = "行数" cols = "列数" > 文本 </textarea>
讲解:1.文本输入域以 <textarea>开端 ,以 </textarea>完毕
2.rows: 输入文本输入域的行数
3.cols : 输入文本输入域的列数
4.在<textarea></textarea>标签之间输入默许值
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>文本域</title>
</head>
<body>
<form method = "post" action = "save.php">
<label>个人简介</label>
<textarea rows = "5" cols = "10">在这里输入内容...</textarea></span>
<input type = "submit" value = "肯定" name = "submit" />
<input type = "reset" value = "重置" name = "reset" />
</form>
</body>
</html>
结果:
个人简介
<lable>在后面会有详解。
使用单选框,复选框让会员选中
在使用表单设计观察表时,为了减少会员的操纵,使用选中框是一个好方法,在HTML中,有单选框和复选框,两者的主要不同是 单选框中会员的选项只能选中一项,而复选框中会员可以任意选中多项,乃至全选。
<input type = "radio/checkbox" value = "值" name = "名称" checked = "checked" />
讲解:
1. type : radio :控件单选框
checkbox : 控件复选框
2. value: 供给数据到效劳器的值
3. name:为控件命名,以备后台程序ASP,PHP使用
4.checked: 当设定 checked = “checked”时,该选项被默许选中。
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>单选框、复选框</title>
</head>
<body>
<form name = "iForm" method = "post" action = "save.php">
你可否喜爱旅行?<br />
<input type = "radio" name = "radioLove" value = "喜爱" checked = "checked"/></span>
<input type = "radio" name = "radioLove" value = "不喜爱"/>
<input type = "radio" name = "radioLove" value = "无所谓"/>
<br /> <br />
你对那些运动感乐趣?<br />
<input type = "checkbox" name = "checkbox1" value = "跑步"/>
<input type = "checkbox" name = "checkbox1" value = "打球" checked = "checked"/>
<input type = "checkbox" name = "checkbox1" value = "爬山" checked = "checked"/>
<input type = "checkbox" name = "checkbox1" value = "健身" />
</form>
</body>
</html>
结果:
你可否喜爱旅行?
你对那些运动感乐趣?
留意:统一组的单选按钮,name的取值必然要一致,这样统一组的单选按钮才可以起到单选的作用。
下拉列表框
使用下拉列表框,节约空间,既可以单选,又可以多选。
单选:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>下拉页表框</title>
</head>
<body>
<form name = "iForm" method = "post" action = "save.php">
<label>喜好:</label>
<select>
<option value = "读书">读书</option></span>
<option value = "运动">运动</option>
<option value = "音乐">音乐</option>
<option value = "旅行">旅行</option>
<option value = "购物">购物</option>
<span style="color:#ff0000;"></select></span>
</form>
</body>
</html>
结果:喜好: 读书运动音乐 旅行购物 (可以下拉)
<option value = "提交值" > 选项</option>
提交值:是向效劳器提交的值
选项:是显示的值
设定 selected = "selected" 则该选项默许被选中。
多选:
就将上面的<select> 改为 <select multiple = "multiple" >就行,然后在widows下ctrl ,同时单击,在Mac 下 Command + 单击
使用提交按钮,提交数据
在表单中有两种按钮可以使用,提交按钮和重置,当会员需要提交信息到效劳器时,需要用到提交按钮。
语法:
<input type = "submit" value = "提交">
讲解:
1.只要当type = "sumit"时,按钮才有提交的作用
2.value: 按钮上显示的字
重置
当会员需要重置表单信息到初始状态时,可以使用重置按钮,只要把type 改为 reset 就行。
<input type = "reset" value = "重置">
讲解:
1.同理提交按钮,只要当type = "reset"时, 按钮才有重置的作用
2.value : 按钮上显示的文字
label标签
label标签不会向会员显现任何非凡的结果,它的作用是为鼠标会员改善了可用性,假如你在label标签内点击文本,就会触发此控件,也就是说,当会员单击选中该label标签时,阅读器会主动将焦点转到和 标签相关的表单控件上(就主动选中和该label标签相关联的表单控件上);
语法:
<label for = "控件id 的名称" >
留意:标签中for 属性的值应当与相关控件的id属性值必然要雷同;
<form>
<label for="male">男</label>
<input type="radio" name="gender" <span style="color:#ff0000;">id="male"</span> />
<br />
<label for="female">女</label>
<input type="radio" name="gender" <span style="color:#990000;">id="female"</span> />
<label for="email">输入你的邮箱地址</label>
<input type="email" <span style="color:#ff6666;">id="email"</span> placeholder="Enter email">
</form>
结果:
男
女
输入你的邮箱地址
以下是本人仿写的,可复选的:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>form中的lable标签</title>
</head>
<body>
<form>
你对什么运动感乐趣:<br/>
<label for = "sport1">慢跑</label>
<input type = "checkbox" name = "sports" id = "sport1"/>
<br />
<label for = "sport2">爬山</label>
<input type = "checkbox" name = "sports" id = "sport2"/>
<br />
<label for = "sport3">篮球</label>
<input type = "checkbox" name = "sports" id = "sport3"/> <br />
</form>
</body>
</html>
结果:
你对什么运动感乐趣:
慢跑
爬山
篮球
相关引荐:
动态生成form表单实现办法
JavaScript实现动态增加Form表单元素的办法示例
HTML Form表单元素的详解
以上就是HTML5中form表单标签用途详解的具体内容,更多请关注百分百源码网其它相关文章!