autocapitalize

autocapitalize 全域性屬性 是一個 列舉 屬性,用於控制是否自動將輸入的文字大寫,以及如果自動大寫,則以何種方式進行。這與以下內容相關

autocapitalize 不會影響在物理鍵盤上輸入時的行為。它影響其他輸入機制的行為,例如移動裝置上的虛擬鍵盤和語音輸入。這可以透過自動大寫每個句子的第一個字母等方式,幫助使用者更快、更容易地輸入資料。

可能的值為

noneoff

不要自動將任何文字大寫。

sentenceson

自動將每個句子的第一個字元大寫。

words

自動將每個單詞的第一個字元大寫。

characters

自動將每個字元大寫。

使用說明

  • autocapitalize 可以設定在 <input><textarea> 元素上,以及它們包含的 <form> 元素上。當在 <form> 元素上設定 autocapitalize 時,它會為所有包含的 <input><textarea> 設定自動大寫行為,覆蓋在包含元素上設定的任何 autocapitalize 值。
  • autocapitalizeurlemailpassword 型別的 <input> 沒有影響,這些型別永遠不會啟用自動大寫。
  • 如果未指定 autocapitalize,則瀏覽器之間採用的預設行為會有所不同。例如
    • Chrome 和 Safari 的預設值為 on/sentences
    • Firefox 的預設值為 off/none

示例

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 表格僅在瀏覽器中載入