HTML中表單是非常常用的元素奠骄,下面的代碼是一組表單的例子,附上jsbin的鏈接:表單
這里表單用了以下幾種元素:
- 單行文本
- 輸入密碼
- 單選框
- 多選框
- 文本域
- 下拉菜單
- 提交按鈕
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<form>
<div class="login">
<label for="username">姓名:</label>
<input id="username" type="text" name="username" placeholder="用戶名"><br>
<label for="password">密碼:</label>
<input id="password" type="password" name="password" placeholder="輸入密碼">
</div>
<div class="sex">
<label>性別:</label>
<input type="radio" name="sex1" value="male"> 男
<input type="radio" name="sex1" value="female"> 女
</div>
<div class="orientation">
<label>取向:</label>
<input type="radio" name="sex2" value="male"> 男
<input type="radio" name="sex2" value="female"> 女
</div>
<div class="hobby">
<label>愛好:</label>
<input type="checkbox" name="hobby" value="dota"> dota
<input type="checkbox" name="hobby" value="tour"> 旅游
<input type="checkbox" name="hobby" value="pet"> 寵物
</div>
<div class="textarea">
<label>評論:</label>
<textarea>
</textarea>
</div>
<div class="mycar">
<label>我的car:</label>
<select name="car">
<option value="BENZ">奔馳</option>
<option value="BMW">寶馬</option>
<option value="FORD">福特</option>
<option value="SB" selected>薩博</option>
</select>
</div>
<div class="submit">
<input type="submit" value="提交">
</div>
</form>
</body>
</html>
瀏覽器顯示的是這樣的: