HTML注冊表單的簡易實現


代碼示例
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注冊</title>
	</head>
	<body>
		<form action="http://localhost:8080/html/register" method="post">
			用戶名
			<input type="text" name="username" /><br>
			密碼
			<input type="password" name="userpwd" /><br>
			確認密碼
			<input type="password" /><br>
			性別:
			男<input type="radio" name="sex" value="男" />
			女<input type="radio" name="sex"  value="女" /><br>
			興趣愛好:
			抽煙<input type="checkbox" name="hobby" value="smoke" />
			喝酒<input type="checkbox" name="hobby" value="drink"  />
			燙頭<input type="checkbox" name="hobby" value="perm" /><br>
			學歷:
			<select name="grade">
				<option value="z">專科</option>
				<option value="b" selected>本科</option>
				<option value="y">研究生</option>
			</select><br>
			簡介:<br>
			<!--文本域沒有value屬性,用戶填寫的就是value-->
			<textarea rows="10" cols="50" name="introduction"></textarea><br>
			<input type="submit" value="注冊" />
			<input type="reset" value="清空" />
		</form>
	</body>
</html>

在這里插入圖片描述

form表單method屬性:

1、get:采用get方式提交的時候,用戶提交的信息會顯示在瀏覽器的地址欄上。

<form action="http://localhost:8080/html/register" method="get">

地址欄顯示:
在這里插入圖片描述
http://localhost:8080/html/register?username=123&userpwd=123&sex=%E7%94%B7&hobby=smoke&hobby=drink&hobby=perm&grade=b&introduction=123
2、post:采用post方式提交的時候,用戶提交的信息不會顯示在瀏覽器地址欄上。

<form action="http://localhost:8080/html/register" method="post">

在這里插入圖片描述
3、當用戶提交的信息中含有敏感信息,例如:密碼。建議采用post方式提交。
4、method屬性不指定,或者指定get,這種情況下都是get。
只有當method屬性指定為post的時候才是post請求。剩下所有的請求都是get請求。(默認為get)
5、post提交的數據格式和get還是一樣的,只不過不在地址欄上顯示出來。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM