1.表单用于搜集不同类型的用户输入,表单由不同类型的标签组成,相关标签及属性用法如下:
(1)<form>标签:定义整体的表单区域
action属性:定义表单数据提交的地址
method属性:定义表单提交的方式,一般有“get"方式和“post"方式
(2)<label>标签为表单元素定义文字标注
(3)<inpuy>标签定义通用的表单元素
type属性:
type="text" 定义单行文本输入框
type="password" 定义密码输入框
type="radio" 定义单选框
type="checkbox" 定义复选框
type="file" 定义上传文件
type="submit" 定义提交按钮
type="reset" 定义重置按钮
type="image" 定义图片作为提交按钮,用src属性定义图片地址
type="hidden" 定义一个隐藏的表单域,用来存储值
value属性 定义表单元素的值
name属性 定义表单元素的名称,此名称是提交数据时的键名
(4)
<textarea>标签:多行文本输入框
<select>标签:下拉表单元素
<option>标签:与<select>标签配合使用,定义下拉表单元素的选项
<body>
<h1>注册表单</h1><form action="" method="post"><!--name相当于键名,有键名才能提交,action不写提交到本地,method使用TCP协议提交,敏感数据用post,反之用get --> <div> <label for="0">用户名:</label> <input type="text" name="username" id="0"/> <!--当for与id吻合,点击用户名即可激活输入框--> </div> <p> <label for="1">密 码:</label> <input type="password" name="password" id="1"/> </p> <p> <label >性 别:</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> </p> <p> <label>爱 好:</label> <!--name,value键值,便于后端存储--> <input type="checkbox" name="like" value="study"/> 学习 <input type="checkbox" name="like" value="languge"/> python <input type="checkbox" name="like" value="architecture"/> django </p> <p> <label>照 片:</label> <input type="file" name="file" /> </p> <p> <label name="introduce" >个人介绍:</label> <textarea ></textarea> <!--textarea多行文本框--> </p> <p> <label>籍贯</label> <select name="site"> <!--select 选择框--> <option value="0">广东</option> <option value="1">台湾</option> <option value="2">澳门</option> <option value="3">香港</option> </select> <input type="hidden" name="hid" value="323"> <!--hidden不显示在页面上--> </p> <p> <input type="submit" name="" value="提交"> <!--<input type="image" src="image/海贼王.jpg" name="">--> <!--会导致提交两次,不建议使用--> <input type="reset" name="" value="重置"> </p></form>
</body>