autocapitalize
autocapitalize 全域性屬性 是一個 列舉 屬性,用於控制是否自動將輸入的文字大寫,以及如果自動大寫,則以何種方式進行。這與以下內容相關
<input>和<textarea>元素。- 任何設定了
contenteditable屬性的元素。
autocapitalize 不會影響在物理鍵盤上輸入時的行為。它影響其他輸入機制的行為,例如移動裝置上的虛擬鍵盤和語音輸入。這可以透過自動大寫每個句子的第一個字母等方式,幫助使用者更快、更容易地輸入資料。
值
可能的值為
none或off-
不要自動將任何文字大寫。
sentences或on-
自動將每個句子的第一個字元大寫。
words-
自動將每個單詞的第一個字元大寫。
characters-
自動將每個字元大寫。
使用說明
autocapitalize可以設定在<input>和<textarea>元素上,以及它們包含的<form>元素上。當在<form>元素上設定autocapitalize時,它會為所有包含的<input>和<textarea>設定自動大寫行為,覆蓋在包含元素上設定的任何autocapitalize值。autocapitalize對url、email或password型別的<input>沒有影響,這些型別永遠不會啟用自動大寫。- 如果未指定
autocapitalize,則瀏覽器之間採用的預設行為會有所不同。例如- Chrome 和 Safari 的預設值為
on/sentences - Firefox 的預設值為
off/none。
- Chrome 和 Safari 的預設值為
示例
HTML
html
<p>Form to test different autocapitalize settings:</p>
<form>
<div>
<label for="default">Default: no autocapitalize set</label>
<input type="text" id="default" name="default" />
</div>
<div>
<label for="off">autocapitalize="off"</label>
<input type="text" id="off" name="off" autocapitalize="off" />
</div>
<div>
<label for="none">autocapitalize="none"</label>
<input type="text" id="none" name="none" autocapitalize="none" />
</div>
<div>
<label for="on">autocapitalize="on"</label>
<input type="text" id="on" name="on" autocapitalize="on" />
</div>
<div>
<label for="sentences">autocapitalize="sentences"</label>
<input
type="text"
id="sentences"
name="sentences"
autocapitalize="sentences" />
</div>
<div>
<label for="words">autocapitalize="words"</label>
<input type="text" id="words" name="words" autocapitalize="words" />
</div>
<div>
<label for="characters">autocapitalize="characters"</label>
<input
type="text"
id="characters"
name="characters"
autocapitalize="characters" />
</div>
<div>
<label for="characters-ta">autocapitalize="characters" on textarea</label>
<textarea
type="text"
id="characters-ta"
name="characters-ta"
autocapitalize="characters">
</textarea>
</div>
</form>
<hr />
<p contenteditable autocapitalize="characters">
This content is editable and has autocapitalize="characters" set on it
</p>
結果
使用虛擬鍵盤或語音輸入測試每個輸入的影響(鍵盤輸入將不起作用)。
規範
| 規範 |
|---|
| HTML 標準 # attr-autocapitalize |
瀏覽器相容性
BCD 表格僅在瀏覽器中載入