初识表单post和get提交
表单
表单元素格式
例子:
- form:表单
- action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
- method: post/get 提交方式
- get方式提交:可以再URL中看到我们提交的信息,不安全,高效
- post :比较安全,传输大文件,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录注册</title>
</head>
<body>
<h1>注册</h1>
<!--
form 表单
action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
method: post/get 提交方式
get方式提交:可以再URL中看到我们提交的信息,不安全,高效
post :比较安全,传输大文件
-->
<form action="first.html" method="post">
<p>名字:<input type="text" name="username"></p>
<p>密码:<input type="password" name="pwd"></p>
<p>
<input type="submit">
<input type="reset">
</p>
</form>
</body>
</html>
输出结果:
(1)get提交
(2)post提交(按住f12在network可以查看密码)
文本框和单选框
例子:
(1)文本框
- value="haha" 默认初始值
- maxlength="8" 最长能写几个字符
- size="30" 文本框的长度
(2)密码框
- input type="password"
(3)单选框标签
- input type="radio"
- value : 单选框的值
- name: 表示组
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录注册</title>
</head>
<body>
<h1>注册</h1>
<!--
form 表单
action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
method: post get 提交方式
get 方式提交:可以再URL中看到我们提交的信息,不安全,高效
post :比较安全,传输大文件
-->
<form action="first.html" method="post">
<!--
文本框
value="haha" 默认初始值
maxlength="8" 最长能写几个字符
size="30" 文本框的长度
-->
<p>名字:<input type="text" name="username" value="haha" maxlength="8"/></p>
<!--
密码框
input type="password"
-->
<p>密码:<input type="password" name="pwd"/></p>
<!--
单选框标签
input type="radio"
value : 单选框的值
name: 表示组
-->
<p>
<input type="radio" value="man" name="sex"/>男
<input type="radio" value="woman" name="sex"/>女
</p>
<p>
<input type="submit"/>
<input type="reset"/>
</p>
</form>
</body>
</html>
输出结果:
按钮和多选按钮
按钮
- input type="button" 普通按钮
- input type="image" 图片按钮
- input type="submit" 提交按钮
- input type="reset" 重置
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录注册</title>
</head>
<body>
<h1>注册</h1>
<!--
form 表单
action : 表单提交的位置,可以是网站,也可以是一个请求处理地址
method: post get 提交方式
get 方式提交:可以再URL中看到我们提交的信息,不安全,高效
post :比较安全,传输大文件
-->
<form action="first.html" method="post">
<!--
文本框
value="haha" 默认初始值
maxlength="8" 最长能写几个字符
size="30" 文本框的长度
-->
<p>名字:<input type="text" name="username" value="haha" maxlength="8"/></p>
<!--
密码框
input type="password"
-->
<p>密码:<input type="password" name="pwd"/></p>
<!--
单选框标签
input type="radio"
value : 单选框的值
name: 表示组
-->
<p>
<input type="radio" value="man" name="sex"/>男
<input type="radio" value="woman" name="sex"/>女
</p>
<!--
多选框
type="checkbox"
-->
<p>
爱好:
<input type="checkbox" value="sleep" name="hobby"/>睡觉
<input type="checkbox" value="code" name="hobby"/>敲代码
<input type="checkbox" value="chat" name="hobby"/>聊天
<input type="checkbox" value="game" name="hobby"/>游戏
</p>
<!--
按钮
input type="button" 普通按钮
input type="image" 图片按钮
input type="submit" 提交按钮
input type="reset" 重置
-->
<p>
按钮:
<input type="button" value="点击变长" name="but1"/>
<input type="image" src="../resource/img/5efaffbac96db.jpg"/>
</p>
<p>
<input type="submit"/>
<input type="reset"/>
</p>
</form>
</body>
</html>
输出结果: