定義:HTML 表單用于搜集不同類型的用戶輸入。
用<form> 元素定義html表單:
<form>
form 表單
</form>
常用屬性:
- Action
action 屬性定義在提交表單時執(zhí)行的動作。 - Method
method 屬性規(guī)定在提交表單時所用的 HTTP 方法(GET 或 POST)。 - Name
規(guī)定識別表單的名稱。 - Target
規(guī)定 action 屬性中地址的目標(biāo)。
HTML 表單包含的常用表單元素:
- 文本輸入
<input type="text">定義用于文本輸入的單行輸入字段:
<form>
<input type="text" name="firstname">
<input type="text" name="lastname">
</form> ```
- 單選框
`<input type="radio">` 定義單選框
<form>
<input type="radio" name="sex" value="男"> 男
<input type="radio" name="sex" value="女"> 女
</form> ```
- 多選框
<input type="checked">定義多選按框
<form>
您喜歡的水果?<br /><br />
<label><input name="Fruit1" type="checkbox" value="" checked/>蘋果 </label>
<label><input name="Fruit2" type="checkbox" value="" />桃子 </label>
<label><input name="Fruit3" type="checkbox" value="" />香蕉 </label>
<label><input name="Fruit4" type="checkbox" value="" />梨 </label>
</form>
- 密碼輸入框
<input type="password">定義密碼輸入
<form>
<input type="password" name="pwd" /></form>
</form> ```
- 按鈕button對象
`<input type="button">` 定義最一般普通的按鈕
<form>
<input type="button" name="button" /></form>
</form> ```
- 文件提交
<input type="file">定義文件上傳提交
<form>
<input type="file" />
</select>
</form>
- submit提交表單
<input type="submit">
<form>
<input type="submit" />
</form>
- select標(biāo)簽
<input type="select">一般用來定義下拉菜單
<form>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>
- label標(biāo)簽
<label for="name">xxx</label>對輸入框和密碼框的文字說明
<form>
<label for="name">姓名</label>
<input type="text" name="name"id=”name“>
</form>