<!-- form 標簽
作用:收集並提交用戶的信息
屬性:
id 表單的id,用於js獲取表單
name 表單的名字,用於js獲取表單
action 表單提交的地址
method 表單提交的方式,常用值為get和post
get(默認)
post
enctype 表單中數據的編碼方式
application/x-www-form-urlencoded(默認)
multipart/form-data
text/plain
form標簽的子標簽(表單域)
注意:1.對於所有的子標簽來講,只有添加name屬性,才可以提交!
2.一般來講,value屬性就是提交的值
3.對於radio和checkbox而言,如果沒有設定value屬性,則提交時值為on
4.對於select而言,select提交的值就是option標簽的value屬性值,如果option標簽沒有設定value屬性值時,默認提交option標簽中間的文本值
5.對於textarea而言,textarea提交的值不是value屬性,而是標簽中間的文本數據
6.對於三個按鈕來講,input和button從本質來講並無區別,而且一般情況不用設置name屬性(即不用提交)
input 屬性
type="text" 文本框
type="password" 密碼框
type="hidden" 隱藏框
type="file" 文件框
type="radio" 單選按鈕
name屬性相同即為一組
type="checkbox" 復選框
name屬性相同即為一組
對於input type="radio"和input type="checkbox"來講,添加check="check"屬性表示默認選中該選項
type="submit" 提交按鈕,提交表單
type="reset" 重置按鈕,重置表單
type="button" 普通按鈕,用於被js調用
對於input type="submit"、input type="reset"和input type="button"來講,value屬性表示按鈕上的文字
select 下拉列表框
給select添加multiple="multiple"的屬性后,就變成多選
需要和option標簽一起使用
textarea 多行文本域
button 按鈕
-->
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <form action="http://www.baidu.com" method="get" enctype="application/x-www-form-urlencoded"> 用戶名:<input type="text" name="username" placeholder="請填寫用戶名"/><br/> 密碼:<input type="password" name="pwd"/><br/> <input type="hidden"e="hiddenfile"/><br/> <input type="file" name="file"/><br/> 性別:<label for="women">女</label><input id="women" type="radio" name="gender" value="女"/> <label for="man">男</label><input id="man" type="radio" name="gender" value="男"><br/> 籃球 <input type="checkbox" name="sports" value="籃球"/> 足球<input type="checkbox" name="sports" value="足球"/> <br/> <select name="city"> <option value="廣州">廣州</option> <option value="深圳">深圳</option> <option value="佛山">佛山</option> </select> <textarea name="inc" cols="30" rows="10">滴滴……</textarea> <input type="button"/><input type="submit"/><input type="reset"/> <button type="submit">提交</button> <button type="reset">重置</button> <button type="button">普通</button> </form> </body> </html>