html学习——表单元素格式、单选框

表单元素格式

属性 说明 type 指定元素的类型,文本框text,密码框password,多选框checkbox,单选框radio,提交按钮submit,重置按钮reset,文件框file,隐藏hidden,图片框image,按钮button name 指定表单元素的名称 value 元素的初始值,type为单选框radio时必须指定一个值 size 指定表单元素的初始宽度,当type为text或者password时,表单元素的大小以字符为单位,对其他的类型,宽度以像素为单位 maxlength type为text或password时,输入的最大字符数 checked type为radio或者checkbox时,指定按钮是否被选中

单选框

上为显示效果,下为代码

<form method="get" action="result.html">
<!--input:输入框标签,默认为text,文本框
	name:为该输入框起一个名字,用来提交数据
	maxlength="8":文本框最多可以输入8个字符
	size="30":文本框的长度时30px
-->
	<p>用户名:<input type="text" name="username" value="文本框初始值"
	maxlength="8" size="30"/></p>
<!--密码框input type="password",密码框输入字符会显示为小圆点-->
	<p>密码:<input type="password" name="pwd"/></p>
<!--radio:单选框
	value:初始值,单选框必须填
	name:成组,否则单选会出现错误
	input标签需要闭合
-->
	<p>性别:
	<input type="radio" value="boy" name="sex"/>男
	<input type="radio" value="girl" name="sex"/>女
	</p>
	
<!--submit提交
	reset重置所有输入框
-->
	<p><input type="submit"/>
	<input type="reset"/></p>
</form>
经验分享 程序员 微信小程序 职场和发展