JavaScript第二課-表單及兩種資料提交方式
1、表單標籤
<legend>註冊區域</legend>
<form action="http://www.baidu.com">
使用者名稱: <input type="text"/ name="user" ><br/>
密碼 :<input type="password" name="paw"/><br/>
性別:<input type="radio" name="sex"/>男<input type="radio"name="sex"/>女<br/>
技術:<input type="checkBox" name = "tech" value="java">java<input type="checkBox">html<input type="checkBox">jsp<br/>
上傳檔案<input type="file"><br/>
按鈕:<input type="button" value="一個按鈕">
<input type="hidden" name="id" value="<%=new Date()%>">
<input type="img" src="7.bmp">
</form>
<select name="country" >//選擇下拉選項
<option value="none">--選擇國家--</option>
<option value="ch">中國</option>
<textarea>//大文字框
</textarea>
<input type="submit"/><input type="reset"/>//提交
</select>
當需要與伺服器,網路互動時才用form標籤,因為它裡面有一個action屬性
2、提交資料(GET和POST)區別..預設是GET方式
(1)GET提交會把資訊顯示在位址列上,所以提交敏感資料不安全,POST安全
(2)位址列存放資料有限,只能存放2083個位元組,大點的用一般用POST提交
(3)封裝格式不同:GET將資料封裝在http訊息頭前面,POST封裝在資料體中,
(4)如果提交中文,用POST在服務端出現亂碼,Tomat解析預設IS8859-1,在服務端request.setCharacterEncoding(“GBK”);
所以提交表單一般用POST方式。
超連結提交都是GET方式。