如何检测在文本区域中输入的文本是RTL [英] How to detect that text typed in text-area is RTL

查看:98
本文介绍了如何检测在文本区域中输入的文本是RTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个textarea,用户可以用英文输入文本(或任何其他从左到右的语言)或使用RTL语言输入文本。

当用户在RTL中写入时,用户必须按右移+ Ctrl键以使文本对齐到右边并且是rtl。但是,在windows(也可能是其他现代操作系统)中,用户可以设置任意组合键来切换语言和文本方向。

我知道如何将文本显示为RTL,但



有没有办法检测在textarea / text-field中键入的文本是否被输入为RTL?

解决方案

我已经想出了一个更简单更好的解决方案。只需将 dir =auto添加到元素中,浏览器就可以完成它了!



请参阅: http://www.w3schools.com/tags/att_global_dir.asp


I have a textarea in which the user can enter text in english (or any other left-to-right language) or in a language that is RTL.

When the user writes in RTL, the user must press Right-shift + ctrl in order to make the text be aligned to the right and be rtl. However, in windows (and probably other modern OSes) the user can set any key combination to switch language and text direction.

I know how to display text as RTL, but how will I know which direction to display?

Is there a way to detect that the text typed in a textarea/text-field was typed as RTL?

解决方案

I've come up to a more simple and nice solution. Just add dir="auto" to the elements and the browser will do it's job!

See: http://www.w3schools.com/tags/att_global_dir.asp

这篇关于如何检测在文本区域中输入的文本是RTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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