强制对WebKit中的textarea进行拼写检查 [英] Force spell check on a textarea in WebKit

查看:156
本文介绍了强制对WebKit中的textarea进行拼写检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基于浏览器的QC /数据输入应用程序,可让人们编辑OCRed文件,这些文件自然会有大量错误。大块的数据放在textareas中,因此可以检查它们,但只有当用户手动将光标放在拼写错误的单词中时才会出现红色下划线。

I'm creating a browser based QC/data entry app that will let people edit OCRed files, which naturally have tons of errors. Chunks of data are put in textareas so they can be checked, but the red underlines only appear when the user manually puts the cursor in a misspelled word.

有没有办法强制WebKit将小红色拼写检查下划线添加到textareas?

Is there a way to force WebKit to add the little red spell check underlines to textareas?

推荐答案

基本上你需要使用选择api移动在每个单词上插入点以使Safari突出显示它。这是一个扫描前千个单词的例子......

Essentially you need to use the selection api to move the insertion point over each word to get Safari to highlight it. Here's an example to scan over the first thousand words...

textarea = document.getElementById("mytextarea");
textarea.focus();

var selection = window.getSelection();
selection.modify("move", "backward", "line");
for (var i = 0; i < 1000; i++ ) {
    selection.modify("move", "forward", "word");
}

// Remove focus from the element, since the word under
// the cursor won't have a misspelling marker.
textarea.blur();

此代码取自 WebKit布局测试套件

这篇关于强制对WebKit中的textarea进行拼写检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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