使用JQuery或JavaScript替代Chrome浏览器的拼写检查语言 [英] Over-ride Chrome Browser spell check language using JQuery or JavaScript

查看:50
本文介绍了使用JQuery或JavaScript替代Chrome浏览器的拼写检查语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的Chrome浏览器55.0.2883.87 m.

I am using the latest Chrome browser Version 55.0.2883.87 m.

在HTML网页上的输入元素上,如何使用JQuery/JavaScript动态替代Chrome浏览器拼写检查器的语言?

On input elements on a HTML web page, how do I dynamically over-ride the language of the Chrome browser spell checker using JQuery/JavaScript?

例如,如果页面以英语(美国)显示并且拼写检查器设置为英语(美国),那么我如何传递de的德语代码,以便内部所有输入元素的文本区域表格将使用德语而不是英语(美国)拼写检查输入内容吗?

For example if the page is displayed in English (US) and the spell checker is set to English (US), how can I pass in the German language code of de, so that the text area of all the input elements inside the form will spell check the input(s) with the German language and not the English (US) language?

这是一个示例HTML文本区域.

Here is an example HTML text area.

<textarea cols="40" id="id_objective_details" maxlength="1000" name="objective_details" rows="10" class="kmw-disabled keymanweb-font textArea01"></textarea>

推荐答案

tl; dr

您可以使用 setAttribute('lang',lang)更改语言,但Chrome不会将 lang 属性用于拼写检查. 将无法解决问题.检查线程以获取更多信息.

You can change the language using setAttribute('lang', lang) but Chrome doesn't use the lang attribute for spellcheck. This is a won't fix issue. Check the thread for more info.

Chrome会使用必须由用户选择的用户词典.(尝试右键单击文本区域->拼写检查->选择语言).此外,用户应安装字典,否则将无法进行拼写检查.

Instead Chrome makes use of the user dictionaries which has to be selected by the user. (Try right-clicking a text-area -> Spellcheck -> Select language). Also the user should have the dictionary installed or else the spellcheck will not be possible.

您可以尝试以下脚本,并请注意,更改lang属性不会生效,但是如上所述手动更改语言会有效.

You can try the following script and note that changing the lang attribute will not have effect but changing the language manually as mentioned above will.

function toLang(lang) {
  document.getElementById('id_objective_details').setAttribute('lang', lang);
}

<h3>Here is some random German text</h3>
<p>Hallo Welt, hallo und hallo wieder Welt.</p>

<h3>Here is some random English text</h3>
<p>Hello world, hello and hi again world.</p>
<textarea cols="40" id="id_objective_details" maxlength="1000" name="objective_details" rows="10" class="kmw-disabled keymanweb-font textArea01" spellcheck="true"></textarea>
<br>
<button onclick="toLang('en')">English check</button>
<button onclick="toLang('de')">German check</button>

您也许可以使用某些外部库,例如 JavaScript SpellCheck

You can perhaps use some external libraries like JavaScript SpellCheck or JQuery SpellCheck to get the job done.

这篇关于使用JQuery或JavaScript替代Chrome浏览器的拼写检查语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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