玩转HTML中表单标签的使用

        html中标签个数不多,但是标签的属性非常之多,所以实际除非专业做前端的,否则没必要把所有的属性都记下来,需要查查w3c文档即可,只需要掌握常见的用法,看得懂即可。详细请查阅:W3C官网网站

表单用于搜集不同类型的用户输入,表单由不同类型的标签组成,相关标签及属性用法如下:

1、<form>标签 定义整体的表单区域

  • action属性 定义表单数据提交地址
  • method属性 定义表单提交的方式,一般有“get”方式和“post”方式

2、<label>标签 为表单元素定义文字标注

3、<input>标签 定义通用的表单元素

  • type属性
    • type="text" 定义单行文本输入框
    • type="password" 定义密码输入框
    • type="radio" 定义单选框
    • type="checkbox" 定义复选框
    • type="file" 定义上传文件
    • type="submit" 定义提交按钮
    • type="reset" 定义重置按钮
    • type="button" 定义一个普通按钮
    • type="image" 定义图片作为提交按钮,用src属性定义图片地址
    • type="hidden" 定义一个隐藏的表单域,用来存储值
  • value属性 定义表单元素的值
  • name属性 定义表单元素的名称,此名称是提交数据时的键名

4、<textarea>标签 定义多行文本输入框

5、<select>标签 定义下拉表单元素

6、<option>标签 与<select>标签配合,定义下拉表单元素中的选项

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>表单</title>
</head>
<body>
	<h1>注册表单</h1>
	 <!--1. form标签定义一个表单区域,其action属性定义表单数据提交的地址,form的method属性定义提交方式,get/post-->
	<form action="http://www.baidu.com/...." method="get">	
		<div>
			<!-- 2. label标签定义表单控件的文字标注,input标签类型为text定义了一个单行文本输入框  -->
			<label for="username">用户名:</label>
			<input type="text" name="username" id="username" />
		</div>		
		<br>
		<div>
			<!--3.  input类型为password定义了一个密码输入框  -->
			<label for="password">密&nbsp;&nbsp;&nbsp;码:</label>
			<input type="password" name="password" id="password">
		</div>
		<br>
		<div>
			<!-- 4. input类型type为radio定义了一个单选框  -->
			<label>性&nbsp;&nbsp;&nbsp;别:</label>
			<input type="radio" name="gender" value="0" id="male"> <label for="male">男</label>
			<input type="radio" name="gender" value="1" id="female"> <label for="female">女</label>
			<input type="radio" name="gender" value="2" id="renyao"> <label for="renyao">中性</label>
		</div>
		<br>
		<div>
			<!-- 5 。input类型为checkbox定义了复选框  -->
			<label>爱&nbsp;&nbsp;&nbsp;好:</label>
			<input type="checkbox" name="like" value="study"> 学习
			<input type="checkbox" name="like" value="python"> python
			<input type="checkbox" name="like" value="frontend"> 前端
			<input type="checkbox" name="like" value="beauty"> 美少女

		</div>

		<br>

		<div>
			<!-- 6 。input类型为file定义上传照片或文件等资源  -->
			<label>美&nbsp;&nbsp;&nbsp;照:</label>
			<input type="file" name="">
		</div>
		<br>

		<div>
			<!-- 7. textarea定义多行文本输入  -->
			<label>个人介绍:</label>
			<textarea name="introduce"></textarea>
		</div>
		
		<br>

		<div>
			<!--8.  select定义下拉列表选择  -->
			<label>籍&nbsp;&nbsp;&nbsp;贯:</label>
			<select name="site">
				<option value="0">北京</option>
				<option value="1">上海</option>					
				<option value="2">河南</option>	
				<option value="3">河北</option>	
				<option value="4">广州</option>	
			</select>

		</div>
		<br>

		<input type="hidden" name="hid01" value="12">

		<div>
			<!--9. input类型为submit定义提交按钮  , 还可以用图片控件代替submit按钮提交,一般会导致提交两次,不建议使用。如:-->
			<input type="submit" name="" value="提交">  
			<!-- <input type="image" src="images/goods.jpg" name=""> -->

            <!-- input类型为reset定义重置按钮  -->
			<input type="reset" name="" value="重置">
		</div>
		
		<br/>
		
		<div >
			<!--<button> 元素定义可点击的按钮-->
			<button type="button" οnclick="alert('Hello World!')">Click Me!</button>
			
		</div>


	</form>
</body>
</html>

效果如下:

2.html内嵌框架

html内嵌框架

<iframe>标签会创建包含另外一个html文件的内联框架(即行内框架),src属性来定义另一个html文件的引用地址,frameborder属性定义边框,scrolling属性定义是否有滚动条,代码如下:

<iframe src="http://www..." frameborder="0" scrolling="no"></iframe>

内嵌框架与a标签配合使用

a标签的target属性可以将链接到的页面直接显示在当前页面的iframe中,代码如下:

<a href="01.html" target="myframe">页面一</a>
<a href="02.html" target="myframe">页面二</a>
<a href="03.html" target="myframe">页面三</a>
<iframe src="01.html" frameborder="0" scrolling="no" name="myframe"></iframe>
发布了248 篇原创文章 · 获赞 1600 · 访问量 267万+

猜你喜欢

转载自blog.csdn.net/qq_26442553/article/details/96433412