久久精品水蜜桃av综合天堂,久久精品丝袜高跟鞋,精品国产肉丝袜久久,国产一区二区三区色噜噜,黑人video粗暴亚裔

HTML input表單屬性

2023-11-22 362

HTML表單是一個(gè)重要的Web技術(shù),主要用于收集用戶的輸入信息。一個(gè)HTML表單由<form>標(biāo)簽定義,此標(biāo)簽內(nèi)可以包含多種表單元素,如<input>、<textarea>、<select>、<button>和<label>等。本教程將介紹 HTML <input> 元素的不同 form* 屬性。

一、form屬性

input 的 form 屬性規(guī)定 <input> 元素所屬的表單。此屬性的值必須等于它所屬的 <form> 元素的 id 屬性。

位于 HTML 表單(但仍是表單的一部分)之外的輸入字段:

<form action="/action_page.php" id="form1">
<label for="fname">姓氏:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="提交">
</form>
<label for="lname">名字:</label>
<input type="text" id="lname" name="lname" form="form1">

二、formaction屬性

nput 的 formaction 屬性規(guī)定當(dāng)提交表單時(shí),對(duì)輸入(數(shù)據(jù))進(jìn)行處理的文件的 URL。該屬性會(huì)覆蓋 <form> 元素的 action 屬性。

formaction 屬性適用于以下輸入類型:submit 和 image。帶有兩個(gè)提交按鈕的 HTML 表單,它們具有不同的操作(action):

<form action="/action_page.php">
<label for="fname">姓氏:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">名字:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="提交">
<input type="submit" formaction="/action_page2.php" value="以管理員提交">
</form>

三、formenctype屬性

input 的 formenctype 屬性指定提交時(shí)應(yīng)如何編碼表單數(shù)據(jù)(僅適用于 method=”post” 的表單)。

注釋:此屬性將覆蓋 <form> 元素的 enctype 屬性。

formenctype 屬性適用于以下輸入類型:submit 和 image。有兩個(gè)提交按鈕的表單。第一個(gè)發(fā)送使用默認(rèn)編碼的表單數(shù)據(jù),第二個(gè)發(fā)送編碼為 “multipart/form-data” 的表單數(shù)據(jù):

<form action="/action_page_binary.asp" method="post">
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<input type="submit" value="提交">
<input type="submit" formenctype="multipart/form-data"
value="以 Multipart/form-data 編碼提交">
</form>

四、formmethod屬性

input 的 formmethod 屬性定義了將表單數(shù)據(jù)發(fā)送到 action URL 的 HTTP 方法。

注釋:此屬性將覆蓋 <form> 元素的 method 屬性。

formmethod 屬性適用于以下輸入類型:submit 和 image。表單數(shù)據(jù)可以作為 URL 變量(method=”get”)或作為 HTTP post 事務(wù)(method=”post”)發(fā)送。

關(guān)于 GET 的注意事項(xiàng):

  • 以名稱/值對(duì)的形式將表單數(shù)據(jù)追加到 URL;
  • 永遠(yuǎn)不要使用 GET 發(fā)送敏感數(shù)據(jù)?。ㄌ峤坏谋韱螖?shù)據(jù)在 URL 中可見?。?;
  • URL 的長(zhǎng)度受到限制(2048 個(gè)字符);
  • 對(duì)于用戶希望將結(jié)果添加為書簽的表單提交很有用;
  • GET 適用于非安全數(shù)據(jù),例如 Google 中的查詢字符串。

關(guān)于 POST 的注意事項(xiàng):

  • 將表單數(shù)據(jù)附加在 HTTP 請(qǐng)求的正文中(不在 URL 中顯示提交的表單數(shù)據(jù));
  • POST 沒有大小限制,可用于發(fā)送大量數(shù)據(jù);
  • 帶有 POST 的表單提交無(wú)法添加書簽。

注意:如果表單數(shù)據(jù)包含敏感信息或個(gè)人信息,請(qǐng)務(wù)必使用 POST!

有兩個(gè)提交按鈕的表單。第一個(gè)使用 method=”get” 發(fā)送表單數(shù)據(jù)。第二個(gè)使用 method=”post” 發(fā)送表單數(shù)據(jù):

<form action="/action_page.php" method="get">
<label for="fname">姓氏:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">名字:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="使用 GET 提交">
<input type="submit" formmethod="post" value="使用 POST 提交">
</form>

五、formtarget屬性

input 的 formtarget 屬性指定一個(gè)名稱或關(guān)鍵字,該名稱或關(guān)鍵字規(guī)定在提交表單后在何處顯示收到的響應(yīng)。

注釋:此屬性將覆蓋 <form> 元素的 target 屬性。

formtarget 屬性適用于以下輸入類型:submit 和 image。

有兩個(gè)提交按鈕且有不同目標(biāo)窗口的表單:

<form action="/action_page.php">
<label for="fname">姓氏:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">名字:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="submit" value="提交">
<input type="submit" formtarget="_blank" value="提交到新窗口/標(biāo)簽頁(yè)">
</form>

六、formnovalidate屬性

input 的 formnovalidate 屬性規(guī)定提交時(shí)不應(yīng)驗(yàn)證 <input> 元素。

注釋:此屬性將覆蓋 <form> 元素的 novalidate 屬性。

formnovalidate 屬性適用于以下輸入類型:submit。

有兩個(gè)提交按鈕的表單(進(jìn)行和不進(jìn)行驗(yàn)證):

<form action="/action_page.php">
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="提交">
<input type="submit" formnovalidate="formnovalidate"
value="不進(jìn)行驗(yàn)證的提交">
</form>

七、novalidate屬性

novalidate 屬性是 <form> 屬性。如果已設(shè)置,novalidate 屬性規(guī)定在提交時(shí)不應(yīng)驗(yàn)證所有表單數(shù)據(jù)。

規(guī)定在提交時(shí)不驗(yàn)證任何表單數(shù)據(jù):

<form action="/action_page.php" novalidate>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email"><br><br>
<input type="submit" value="提交">
</form>
  • 廣告合作

  • QQ群號(hào):4114653

溫馨提示:
1、本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。郵箱:2942802716#qq.com(#改為@)。 2、本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)裁,轉(zhuǎn)載請(qǐng)注明出處“站長(zhǎng)百科”和原文地址。
HTML input表單屬性
上一篇: HTML輸入屬性
HTML input表單屬性
下一篇: HTML畫布