Web学习第二天

HTML中的表单标签

input标签

用来获取用户输入信息的标签,其属性如下:

  1. type:属性值有很多,并且不同的属性值会显示出不同的样式
    1. text :文本框,输入文本(如何在input中没有设置type属性,默认就是text)
    2. password:密码框(定义密文字段)
    3. radio:单选按钮(注意:name要写成一样,才能做到单一选择)
    4. checkbox:复选框(注意:name要写成一样,才能做到属于一组数据)
    5. date:日期
    6. file:上传文件组件
    7. submit:提交按钮,将表单数据提交到服务器
    8. reset:重置按钮,恢复表单至初始化状态
    9. hidden:隐藏字段,数据也会发给服务器,但在浏览器中不显示
    10. button:普通的按钮
  2. name:表单提交数据到服务器必须设置name属性,name和value组成一组键值对
  3. value:默认值
  4. checked:单选框和复选框的默认选择属性
  5. readonly:设置标签为只读属性
  6. size:大小
  7. maxlength:允许输入的最大长度
  8. placeholder:占位属性,常用于文本的占位

select、option标签

下拉列表,不会独占一行,通常结合option来使用。

  1. select属性:
    1. name:发送给服务器的名称
    2. size:可见下拉框的数量
    3. multiple:加上此属性表示下拉框可以多选,一般不建议使用
  2. option属性:
    1. selected:默认选中
    2. value:发给服务器的具体值,如果不写,发送内容为option标签中的内容

texearea标签

文本域,用于输入多行文本内容,其属性如下:

  1. cols:文本域的列数
  2. rows:文本域的行数
  3. name:发给服务器的名称
  4. value:发给服务器的内容

利用以上标签实现注册表单:

代码如下:

<html>
<meta content="text/html" charset="utf-8">
<head>
<title>注册表单</title>
</head>
<body>
	<table border="1" cellspacing="0" align="center">
		<tr>
			<th align="left">用户名:</th>
			<!-- text文本 -->
			<th align="left"><input type="text" /></th>
		</tr>
		<tr>
			<th align="left">密码:</th>
			<!-- password密码 -->
			<th align="left"><input type="password" /></th>
		</tr>
		<tr>
			<th align="left">确认密码:</th>
			<!-- password密码 -->
			<th align="left"><input type="password" /></th>
		</tr>
		<tr>
			<th align="left">昵称:</th>
			<!-- text文本-->
			<th align="left"><input type="text" /></th>
		</tr>
		<tr>
			<th align="left">性别:</th>
			<!-- radio单选框 -->
			<th align="left"><input type="radio" name="sex" />男 <input
				type="radio" name="sex" checked />女</th>
		</tr>
		<tr>
			<th align="left">爱好:</th>
			<!-- checkbox复选框 -->
			<th align="left"><input type="checkbox" name="sex" />编程 <input
				type="checkbox" name="sex" />足球 <input type="checkbox" name="sex" />音乐
			</th>
		</tr>
		<tr>
			<th align="left">生日:</th>
			<!-- date日期 -->
			<th align="left"><input type="date" /></th>
		</tr>
		<tr>
			<th align="left">头像:</th>
			<!-- file上传文件组件 -->
			<th align="left"><input type="file" /></th>
		</tr>
		<tr>
			<th align="left">城市:</th>
			<!-- select下拉框  option标签  selected默认选择  -->
			<th align="left"><select style="width: 60px;">
					<option>郑州</option>
					<option style="display: none" selected></option>
					<option>北京</option>
					<option>杭州</option>
					<option>上海</option>
			</select></th>
		</tr>
		<tr>
			<th align="left">自我介绍:</th>
			<!-- textarea文本域 -->
			<th align="left"><textarea cols="31" rows="3" resize="none"></textarea>
			</th>
		</tr>
		<tr>
			<!-- readonly只读属性 -->
			<th align="left">验证码:<input type="text" readonly value="60xy"
				style="width: 40px" />
			</th>
			<th align="left"><input type="text" /></th>
		</tr>
		<tr>
			<!-- submit注册按钮   reset重置按钮  -->
			<th colspan="2"><input type="submit" value="注册" /> <input
				type="reset" value="重置" /></th>
		</tr>
	</table>
</body>
</html>

运行效果图如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

5t李

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值