如何在 HTML 中指定元素是否需要進行拼寫和語法檢查?


可以使用 HTML 拼寫檢查工具查詢文字欄位中的語法和拼寫錯誤。

使用 spellcheck 屬性,可以為 HTML 表單新增拼寫檢查功能。spellcheck 屬性是一個列舉屬性,用於指定是否檢查 HTML 元素中的錯誤。它與 HTML 的 "input" 和 "textarea" 欄位相容。

語法

以下是如何在 HTML 中包含拼寫檢查的語法:

<! -- For input field -->.
<input type="text" spellcheck="value">
<! -- For input text area -->.
<textarea type="text" spellcheck="value"></textarea>

以下是一些示例……

示例:Spellcheck 值=”true”

在以下示例中,我們將 spellcheck 屬性設定為 “true” 以在 HTML 中啟用拼寫檢查。

<!DOCTYPE html> <html> <body> <form> <p>Name:<input type="text" spellcheck="true"></p> <p>Address:<textarea spellcheck="true"></textarea></p> <button type="reset">Reset</button> </form> </body> </html>

輸出

執行指令碼後,將彈出一個輸出視窗,其中包含一個輸入區域,使用者可以在其中輸入詳細資訊。如果存在任何拼寫錯誤,該區域將用紅線標出,因為我們設定了 spellcheck="true"。

示例:Spellcheck 值=”false”

在以下示例中,我們將 spellcheck 屬性設定為 “false” 以在 HTML 中停用拼寫檢查。

<!DOCTYPE html> <html> <body> <form> <p>Name:<input type="text" spellcheck="false"></p> <p>Address:<textarea spellcheck="false"></textarea></p> <button type="reset">Reset</button> </form> </body> </html>

輸出

執行指令碼時,它會檢查 spellcheck 值,即 spellcheck="false"。使用者無法檢查自己輸入的拼寫是否正確。

更新於:2022年9月5日

309 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.