HTML5中的常用表单元素使用例子


1、form - 表单
element/form/form.html

<!doctype html>
<html>
<head>
<title>form</title>
</head>
<body>

<!--
form - 表单,用于提交子元素数据到服务端
accept-charset - 指定提交数据的编码格式
action - 提交的目标地址
autocomplete - 是否对所有子元素启用自动完成功能(on 或 off)
enctype - 编码类型(application/x-www-form-urlencoded 或 multipart/form-data 或 text/plain)
method - form 的 method(默认是 GET)
name - form 的 name
novalidate - 提交时是否不需要验证,boolean 类型
target - form 的 target
-->

<form action="#">
<input type="text" name="txt" value="webabcd" />
<input type="submit" name="btn" value="submit" />
</form>

</body>
</html>


2、label - 关联其它元素
element/form/label.html

<!doctype html>
<html>
<head>
<title>label</title>
</head>
<body>

<!--
label - 关联其它元素
form - 指定 label 所属的表单,多个用空格分开
for - 关联元素的 id

DOM
form, htmlFor
control - 返回 label 所关联的元素
-->

<label><input type="checkbox" /> checkbox title</label>

<br />

<input id="chk" type="checkbox" />
<label id="lbl" for="chk">checkbox title</label>

<script type="text/javascript">
var lbl = document.getElementById("lbl");
alert(document.getElementById(
"lbl").htmlFor);
alert(document.getElementById(
"lbl").control.outerHTML);
</script>
</body>
</html>


3、button - 按钮元素
element/form/button.html

<!doctype html>
<html>
<head>
<title>button</title>
</head>
<body>

<!--
button - 按钮元素
autofocus - 页面加载后是否自动置为焦点,boolean 类型
disabled - 是否无效,boolean 类型
form - 指定关联的 form 的 id
formaction - 指定关联 form 的 action
formenctype - 指定关联 form 的编码类型
formmethod - 指定关联 form 的 method
formnovalidate - 指定关联 form 在提交时是否不需要验证,boolean 类型
formtarget - 指定关联 form 的 target
type - 按钮类型(button 或 submit 或 reset)
-->

<button type="button">button</button>

</body>
</html>


4、select - 下拉列表框元素, option - 选项, optgroup - 选项组
element/form/select_option_optgroup.html

<!doctype html>
<html>
<head>
<title>select option optgroup</title>
</head>
<body>
<!--
select - 下拉列表框元素
autofocus, disabled, form, name, required, size
multiple - 是否可多选,boolean 类型

option - 选项
disabled, label, selected, value

optgroup - 选项组
disabled, label
-->

<select>
<option value="1" label="aaa" />
<option value="2" label="bbb" />
<option value="3" label="ccc" selected />
<option value="4" label="ddd" />
<option value="5" label="eee" />
</select>

<select multiple>
<option value="1">aaa</option>
<option value="2">bbb </option>
<option value="3" selected>ccc</option>
<option value="4" selected>ddd</option>
<option value="5">eee </option>
</select>

<select>
<optgroup label="optgroup 1">
<option value="1">aaa</option>
<option value="2">bbb </option>
</optgroup>
<optgroup label="optgroup 2">
<option value="3">ccc</option>
<option value="4">ddd </option>
</optgroup>
<optgroup label="optgroup 3">
<option value="5" selected>eee</option>
<option value="6">fff </option>
</optgroup>
</select>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值