2012-06-18 41 views
9

Me encuentro con este problema. Tengo un área de texto que solo quiero usar el corrector ortográfico cuando está enfocado.¿Hay alguna forma de desactivar el corrector ortográfico en un área de texto de Chrome con JavaScript o CSS?

<textarea id="editor"></textarea> 

$('#editor').focusin(function(){ 
    $(this).attr('spellcheck', true); 
}); 

$('#editor').focusout(function(){ 
    $(this).attr('spellcheck', false); 
}); 

En cromo, si una palabra está mal escrita hay una línea roja debajo de la palabra. Incluso si desactivo el corrector ortográfico, la línea roja aún existe. ¿Cómo elimino este marcador?

+0

Suena como una pregunta para SuperUser más que Stack Overflow. – gdoron

+6

Es un problema de programación. Necesito hacer esto en el código –

+0

Recreate un área de texto con el mismo texto, pero antes de ponerlo en DOM, haz 'spellcheck' false primero. –

Respuesta

0

tiene todo resuelto

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

el bucle método toogleSpellingcheck través de todas las palabras, que se puede optimizar por palabras mínimas de bucle en lugar de caracteres, también esta necesidad jQuery símbolo de intercalación de plugin

que es un poco complicado, pero funciona, alguien tiene sugerencias sobre mejoras favor Avísame

3

He utilizado esta pregunta para obtener una respuesta a su pregunta: Force spell check on a textarea in WebKit

HTML:

<textarea id="editor" spellcheck="true"></textarea> 

Javascript:

$('#editor').focusin(function(){ 
    $(this).attr('spellcheck', true); 
}); 

$('#editor').focusout(function() { 
    $(this).attr('spellcheck', false); 
    forceSpellcheck($(this)); 
}); 

    var canCheck = true; 
    function forceSpellcheck($textarea) { 
    if (canCheck) { 
    canCheck = false; 

    $textarea.focus(); 
    $textarea.attr('spellcheck', false); 
    var characterCount = $textarea.val().length; 

    var selection = window.getSelection(); 
    for (var i = 0; i < characterCount; i++) { 
     selection.modify("move", "backward", "character"); 
    } 

    // Remove focus from the element, since the word under 
    // the cursor won't have a misspelling marker. 
    $textarea.blur(); 
    } else { 
    canCheck = true; 
    } 
}​ 

Demostración: http://jsfiddle.net/QgsRU/13/

+2

Ese bucle con constante 1000 no se ve tan bien. puede obtener la cantidad de palabras con '.split (\ s)'. Soluciona eso y obtuviste mi voto favorable. – gdoron

+0

A decir verdad, no estudié ese método. Solo copié y pegué. Voy a investigar eso. Gracias gdoron! – Chango

+0

Ni siquiera funciona en absoluto. Cuelgo mi navegador, y no puedo desenfocarlo. –

Cuestiones relacionadas