HTML spellcheck in contenteditable div not working after span

拜拜、爱过 提交于 2019-11-29 14:39:17

This is a feature of the implementation of spellcheck in Chrome (and IE): the browser checks user input, not initial (prefilled) content or programmatically inserted content. If you e.g. edit prefilled content, perhaps just by appending a period, the browser may run spell checking on it. The exact conditions for this seem to vary. Sometimes just selecting a word by double-clicking causes spelling check. Sometimes it is essential that a word is ended by some punctuation mark. Nesting of elements may affect too.

Such behavior is implicitly referred to in WHATWG HTML (“HTML Living Standard”), clause Spelling and grammar checking: it describes the forceSpellCheck() (no implementations yet, it seems), which “forces the user agent to report spelling and grammar errors on the element (if checking is enabled), even if the user has never focused the element. (If the method is not invoked, user agents can hide errors in text that wasn't just entered by the user.)”

Anyway, the conclusion is that you should not expect initial content to be spellchecked. It should be checked, with some suitable tools, before generating the page.

The spellcheck attribute has been defined vaguely and in many ways browser-dependent. And browser-dependent it is. Firefox runs spelling checks on initial content too (but it, like other browsers, supports only a handful of languages.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!