HTMLElement: spellcheck 屬性
HTMLElement 介面的 spellcheck 屬性表示一個布林值,用於控制拼寫檢查提示。它可用於所有 HTML 元素,但並非對所有元素都有影響。
它反映了 spellcheck HTML 全域性屬性的值。
值
如果元素中文字內容的拼寫和語法可以被檢查,則為 true;否則為 false。
示例
以下示例展示瞭如何透過指令碼控制拼寫檢查提示。
html
<div>
<span id="sc-label">The spelling and grammar may be checked: </span>
<span id="sc-element" contenteditable="true" spellcheck="true">test</span>
</div>
<input id="sc-controller" type="checkbox" checked />Enable spelling and grammar
check
js
const label = document.getElementById("sc-label");
const element = document.getElementById("sc-element");
const controller = document.getElementById("sc-controller");
controller.addEventListener("change", (e) => {
if (controller.checked) {
element.spellcheck = true;
label.innerText = "The spelling and grammar may be checked: ";
} else {
element.spellcheck = false;
label.innerText = "The spelling and grammar may not be checked: ";
}
});
請注意,您必須在瀏覽器設定中啟用拼寫和語法檢查。
規範
| 規範 |
|---|
| HTML # dom-spellcheck-dev |
瀏覽器相容性
載入中…
另見
spellcheckHTML 全域性屬性