更改语言后更改文本对齐 [英] Change Text Align After Change Language

查看:79
本文介绍了更改语言后更改文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML中有这样的文本区域:

I have a text area in HTML like this:

<textarea name="tx1" style="direction:ltr;"></textarea>

现在,当用户将语言更改为阿拉伯语时,我想更改输入文本的方向或对齐它们. Whithout我想知道的任何问题,任何按钮或任何提交我都想知道他在输入时所用的语言.如果用户是阿拉伯语,则将textarea对齐设置为right.如果英语将其设置为左.

Now, I want to change the direction of input text or align of them when the user changes the language to arabic. Whithout Any Question or Any Button Or Any Submit I Want to know The user language when he is typing. if the user is arabic, set the textarea align to right. if english set it to left.

推荐答案

我能想到的唯一方法是检查文本区域的值

the only way i can think is checking the value of text area

var arabicPattern = /[\u0600-\u06FF]/;

$('#text').bind('input propertychange', function(ev) {

    var text = ev.target.value;

    if (arabicPattern.test(text)) {
        // arabic;
        $('#text').css('direction', 'rtl')

    }


});

但是仅检查阿拉伯语是不够的.您必须检查每个rtl脚本

But for checking only for arabic is not enought. You must check for every rtl scripts

工作示例

这篇关于更改语言后更改文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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