有没有办法关闭文本区域中的拼写检查? [英] Is there a way to turn off spell check in a textarea?

查看:75
本文介绍了有没有办法关闭文本区域中的拼写检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个问题.我有一个文本区域,只在焦点对准时才想使用拼写检查.

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);
});

在chrome中,如果一个单词拼写错误,则该单词下方会出现一条红线.即使我关闭了拼写检查器,红线仍然存在.如何删除该标记?

In chrome, if a word is misspelled there is a red line under the word. Even if I turn off the spell checker, the red line still exists. How do I remove this marker?

推荐答案

搞清楚了

function bindEditorFocus() {
    var $editor = $('#editor');
    $editor.focusin(function(){
        $(this).attr('spellcheck', true);
        toggleSpellingcheck(); // 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});
    }
}

toogleSpellingcheck方法遍历所有单词,可以对其进行优化以遍历单词而不是字符,但这需要jquery插入符

the toogleSpellingcheck method loop through all words, it can be optimized to loop through words instead of characters, but this would need the jquery caret plugin

有点混乱,但是可以用,有人对改进有建议,请告诉我

it's a bit messy, but works, anyone got suggestions on improvements please let me know

这篇关于有没有办法关闭文本区域中的拼写检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆