禁用编辑后,红色拼写检查波形仍保持在镀铬状态 [英] Red spellcheck squiggles remain in chrome after editing is disabled
问题描述
更新:这已被确定为Chrome中的一个错误。 (谢谢@ michael-robinson)
在Chrome(至少v22)中,我注意到即使在禁用了contentEditable后,拼写检查红色弯曲 。
我做了一个jsfiddle来演示:
更新2 :上面的解决方案使用了innerHTML,它删除了销毁事件处理程序。新的方法使用jQuery的 clone()
方法(在深度克隆模式下)创建对象的副本(通过事件处理程序进行复制),并具有自定义功能以保存对选择的引用,并在之后进行恢复。请注意,选择保存/恢复功能不会在ie6-8中工作,但我认为这是可以接受的,因为问题标记为Chrome。更新JSfiddle: http://jsfiddle.net/RegVn/23/
UPDATE: This has been identified as a bug in Chrome. (Thanks @michael-robinson)
In Chrome (v22 at least), I notice that it's possible for spellchecking "red squiggly" underlines to remain even after contentEditable has been disabled.
I made a jsfiddle to demonstrate: jsfiddle demo.
Even if I set the attribute spellcheck="false"
before disabling contentEditable
, they remain.
Anyone know how a nice way to solve or work around this? Ideally I'd retain the built-in spell checking functionality when the content is editable.
Have you tried setting (didn't work, see other solution below)display: none
(using CSS) and then setting the display back to what it was? Might force Chrome to redraw the element...
Alternatively, you could create a copy of the element (but with contenteditable disabled) placing it just after the original element and deleting the original element.
UPDATE 1: first solution didn't work, but second one does. Updated JSfiddle http://jsfiddle.net/RegVn/6/
UPDATE 2: above solution uses innerHTML which removes destroys event handlers. It also destroys the selection/caret position.
New method uses jQuery's clone()
method (in deep clone mode) to create a copy of the object (which copies over the event handlers), and has custom functions to save a reference to the selection, and restore it afterwards. Note that the selection save/restore functions wont work in ie6-8, but I thought that this was acceptable as the question is tagged Chrome. Updated JSfiddle: http://jsfiddle.net/RegVn/23/
这篇关于禁用编辑后,红色拼写检查波形仍保持在镀铬状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!