表单标签的基本属性
input type = “text” 文本输入框 value设置默认显示内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/>
</form>
</body>
input type = “password” 是密码框 value设置默认显示内容
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/>
</form>
</body>
input type = “redio” 是单选框 name属性可以对其进行分组 checked="checked"表示默认选中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
</form>
</body>
Input type=“checkbox” 复选框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++
</form>
</body>
Input type=“reset” 是重置按钮 value属性修改按钮上的文本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/>
</form>
</body>
这是点击重置按钮之前的页面
这是点击了重置按钮后的页面,都编程了页面设置的默认初始值
Input type=“submit” 是提交按钮 value属性修改按钮上的文本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/><br/>
<input type="submit" value="提交"/><br/>
</form>
</body>
点击提交按钮之后url地址栏就多出了一串内容,这就说名提交成功,这里默认用的是GET方式提交,所以url地址栏会显示,这里后面会提及到,现在不用管
Input type=“button” 是按钮 value属性可以修改按钮上的文本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/><br/>
<input type="submit" value="提交"/><br/>
<input type="button" value="保存到草稿箱"/>
</form>
</body>
Input type=“file” 是文本上传域
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/><br/>
<input type="submit" value="提交"/><br/>
<input type="button" value="保存到草稿箱"/><br/>
<input type="file"/>
</form>
</body>
点击选择文件按钮后就会自动弹出选择文件的对话框
Input type=“hidden” 是隐藏域 当我们要发送某些信息,而这些信息,不需要用户参与,就可以使用隐藏域(提交的时候同时发展送给服务器)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/><br/>
<input type="submit" value="提交"/><br/>
<input type="button" value="保存到草稿箱"/><br/>
<input type="hidden"/>
<input type="file" name="abc" value ="acc"/>
</form>
</body>
网页上并不会显示隐藏域
select 标签是下拉列表框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/><br/>
<input type="submit" value="提交"/><br/>
<input type="button" value="保存到草稿箱"/><br/>
国籍:<select>
<option>--请选择国籍--<option/>
<option>中国<option/>
<option>俄罗斯<option/>
<option>巴基斯坦<option/>
<select/>
</form>
</body>
textarea 标签表示多行文本输框
rows属性设置可以显示几行的高度
cols属性设置每行可以显示几个字符宽度``
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
用户名:<input type = "text"/ value="请输入你的名字"/><br/>
密码:<input type="password" value="请输入你的密码"/><br/>
性别:<input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女<br/>
你最喜欢的语言是<br/>
<input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++<br/>
<input type="reset" value="重置"/><br/>
<input type="submit" value="提交"/><br/>
<input type="button" value="保存到草稿箱"/><br/>
国籍:<select>
<option>--请选择国籍--<option/>
<option>中国<option/>
<option>俄罗斯<option/>
<option>巴基斯坦<option/>
<select/><br/>
自我评价:<textarea rows="5" cols="20">请进行客观的评价</textarea>
</form>
</body>
目前一个简单的表单提交的页面就已经做好了,但是这个样式有点不太美观,我们可以用table标签来给页面更加格式化,更美观
table标签是表格标签
tr是行标签
th是列标签
td是单元格标签
b标签是加粗标签
colspan属性设置跨行
rowspan属性设置跨行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form>
<table>
<tr>
<td>用户名:</td>
<td><input type = "text"/ value="请输入你的名字"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" value="请输入你的密码"/></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女</td>
</tr>
<tr>
<td>你最喜欢的语言是</td>
<td><input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++</td>
</tr>
<tr>
<td>国籍:</td>
<td><select>
<option>--请选择国籍--<option/>
<option>中国<option/>
<option>俄罗斯<option/>
<option>巴基斯坦<option/>
<select/></td>
</tr>
<tr>
<td>自我评价:</td>
<td>
<textarea rows="5" cols="20">请进行客观的评价</textarea></td>
</tr>
<tr>
<td><input type="reset" value="重置"/></td>
<td><input type="button" value="保存到草稿箱"/></td>
<td><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
表单提交的时候,数据没有发送给服务器的三种情况
1,表单没有name属性值
2,单选,复选(下拉列表中的option标签)都需要添加value属性,以便发送给服务器
3,表单项不在提交的from标签中
GET请求的特点:
1,浏览器地址栏中的地址是action属性[+?+请求参数]
请求参数的格式是:name=value&name=value
2,不安全
3,他有数据长度的限制
POST请求的特点:
1,浏览器地址栏中只有action属性
2,相对于GET请求要安全
action属性设置提交的服务器网址
method属性设置设置提交的方式GET(默认值)或POST
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML &&CSS</title>
</head>
<body>
<form action="http://localhost:8080" method="post">
<input type="hidden" name="action" value="login"/>
<table>
<tr>
<td>用户名:</td>
<td><input type = "text"/ value="请输入你的名字"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" value="请输入你的密码"/></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name = "sex"/>男
<input type="radio" name = "sex" checked="checked"/>女</td>
</tr>
<tr>
<td>你最喜欢的语言是</td>
<td><input type="checkbox" checked="checked"/>java
<input type="checkbox" />python
<input type="checkbox" />c++</td>
</tr>
<tr>
<td>国籍:</td>
<td><select name="country">
<option>--请选择国籍--<option/>
<option>中国<option/>
<option>俄罗斯<option/>
<option>巴基斯坦<option/>
<select/></td>
</tr>
<tr>
<td>自我评价:</td>
<td>
<textarea name="desc" rows="5" cols="20">请进行客观的评价</textarea></td>
</tr>
<tr>
<td><input type="reset" value="重置"/></td>
<td><input type="button" value="保存到草稿箱"/></td>
<td><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
现在点击提交按钮,页面就会把数据提交到http://localhost:8080的位置,并且不会在url地址栏里面显示提交的内容,保护了用户的隐私,