有没有办法在Chrome中使用JavaScript或CSS关闭文本区域的拼写检查? [英] Is there a way to turn off spell check in a text area in Chrome using JavaScript or CSS?
问题描述
< textarea id =editor>>我有一个textarea,我只想在焦点时使用拼写检查。 ;< / textarea的>
$ b $('#editor')。focusin(function(){
$(this).attr('spellcheck',true);
});
$ b $('#editor')。focusout(function(){
$(this).attr('spellcheck',false);
});
在chrome中,如果一个单词拼写错误,该单词下面会出现一条红线。即使我关闭拼写检查器,红线仍然存在。如何删除这个标记?
p $ p> function bindEditorFocus(){
var $ editor = $('#editor');
$ editor.focusin(function(){
$(this).attr('spellcheck',true);
googleSpellingcheck(); //遍历所有单词以添加标记
});
$ editorblur(function(){
$ editor.attr('spellcheck',false);
$ editor.unbind(); //我需要解除所有函数避免循环
toogleSpellingcheck(); //遍历所有单词以删除标记
$ editor.blur(); //离开文本区域
bindEditorFocus(); // rebind所有功能
});
$ b函数toogleSpellingcheck(){
//这将遍历所有单词
var $ editor = $('#editor');
var text = $ editor.val();
for(var i = 0; i< text.length; i ++){
$ editor.caret({start:i,end:i});
}
}
toogleSpellingcheck方法遍历所有单词,它可以优化循环槽词而不是字符,也需要jquery caret插件
这有点麻烦,但工程,任何人都有改进建议,请让我知道
I run into this problem. I have a textarea which I only want to use spell check when it's in focus.
<textarea id="editor"></textarea>
$('#editor').focusin(function(){
$(this).attr('spellcheck', true);
});
$('#editor').focusout(function(){
$(this).attr('spellcheck', false);
});
In chrome, if a word is misspelled there is a red line under the word. Even if I turn off spell checker, the red line still exists. How do I remove this marker?
got it figured out
function bindEditorFocus() {
var $editor = $('#editor');
$editor.focusin(function(){
$(this).attr('spellcheck', true);
googleSpellingcheck(); // loop through all words to add marker
});
$editorblur(function(){
$editor.attr('spellcheck', false);
$editor.unbind(); // I need to unbind all function to avoid a loop
toogleSpellingcheck(); // loop through all words to remove marker
$editor.blur(); //get out of text area
bindEditorFocus(); // rebind all functions
});
}
function toogleSpellingcheck(){
//this will loop through all words
var $editor = $('#editor');
var text = $editor.val();
for (var i = 0; i < text.length; i++) {
$editor.caret({start:i,end:i});
}
}
the toogleSpellingcheck method loop through all words, it can be optimized by loop trough words instead of characters, also this need jquery caret plugin
it's a bit messy, but works, anyone got suggestions on improvements please let me know
这篇关于有没有办法在Chrome中使用JavaScript或CSS关闭文本区域的拼写检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!