html5规定是否对元素进行拼写和语法检查的属性spellcheck

2020-07-26 22:06:04

实例

进行拼写检查的可编辑段落:

<p contenteditable="true" spellcheck="true">这是一个段落。</p>

浏览器支持

IE、Firefox、Chrome、SafariOpera

定义和用法

spellcheck 属性规定是否对元素进行拼写和语法检查。

可以对以下内容进行拼写检查:

input 元素中的文本值(非密码)

<textarea> 元素中的文本

可编辑元素中的文本

HTML 4.01 与 HTML5 之间的差异

spellcheck 属性是 HTML5 中的新属性。

语法

<element spellcheck="true|false">

属性值

描述
true对元素进行拼写和语法检查
false不检查元素。

html5的spellcheck属性(拼写、文法检查)

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>spellcheck属性的使用</title> </head> <body> <style>.ac{border:1px solid #ff7300;width:200px;height:100px;}</style><pre>1.<b>输入完某个单词后,进行按空格键,就可以看到这是不是错误的单词了。</b>2.spellcheck="true"、'false'、"",值为true和""时,代表检查。。【空字符串为什么检查:就跟input其他属性一样,你设置个readonly就是只读( readonly=""),再加个值描述的更准确。】3.使用场合:   1.类型为text型的input元素,但input类型为text型的input元素,但input="password"不行(原因:你是密码哎,都是星号还检查个啥玩意,密码本身就是不同字母组合而出的)。   2.textarea元素   3.spellcheck属性,html5中的所有元素都可以指定,对于不是输入栏的元素,须指定contenteditable="true" 编辑属性,才能使用。(如div什么的。)4.现代浏览器都支持以及IE10   </pre><p>检测<textarea spellcheck="true" >absolute testK</textarea> </p> <p>不检测 <textarea spellcheck="false"></textarea> </p> <div contenteditable="true" spellcheck class="ac">div absolute testK</div><p>readonly="":<input readonly=""/></p><p><input type="password" spellcheck="true"/></p></body> </html>