例子
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <body>
- <form action="" method="post">
- <fieldset>
- <legend>用户登录表单legend>
-
- <label>
- 用户名:<input type="text" id="userName" placeholder="请输入用户名"/>
- label>
-
- <label>
- 密码:<input type="password" id="userPassword"/>
- label>
- <br /><br />
- <input type="submit" value="提交" id="submitBtin"/>
- fieldset>
- form>
-
- <form>
- <fieldset>
- <legend>用户登录表单legend>
- <p>方式一p>
- <label>
- 用户名:<input type="text" id="userName" placeholder="请输入用户名"/>
-
- label>
- <p>方式二p>
- <label for="userName">用户名:label>
- <input type="text" id="userName" placeholder="请输入用户名">
- fieldset>
-
- form>
-
-
-
- body>
- html>
每一个from标签都有一个action属性,其定义了提交数据的URL。
Method属性,定义了提交表单数据的两种方式get和post
Get方式:将表单数据以名称/值对的形式附加在action所定义的URL末尾来进行传输,默认情况是采用get方式
注意:
Get中URL中的参数是可见的,所以说是不安全的
URL长度有限的,get方式常用于短表单的数据传递
Post方式:将表单数据放在HTTP头信息中进行传输。(安全)有以下情景
用户上传文件时
表单数据非常长
包含保密的数据
3,
用于为input元素定义描述信息,例如表单控件的名称等,还可以扩大表单控件的焦点区域。
例子:
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <body>
-
-
- <form>
- <fieldset>
- <legend>用户登录表单legend>
- <p>方式一p>
- <label>
- 用户名:<input type="text" id="userName" placeholder="请输入用户名"/>
-
- label>
- <p>方式二p>
- <label for="userName">用户名:label>
- <input type="text" id="userName" placeholder="请输入用户名">
- fieldset>
-
- form>
-
-
-
- body>
- html>
4,