自动更改文本框的文本方向

编程入门 行业动态 更新时间:2024-10-25 08:23:37
本文介绍了自动更改文本框的文本方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当您访问Facebook并想要发表评论时,关于您为键盘选择的语言,当您点击文本框撰写评论时,文本框的方向会自动更改。如果您为键盘选择了阿拉伯语,文本框将自动获取RTL方向。 任何想法如何实现?我想在我的网络应用程序中使用它。

非常感谢您的帮助,我非常感谢。

您可以使用CSS direction 属性实现这一点:

输入{ direction:rtl; }

更新

要根据用户输入动态更改文本的方向,您可以检查输入的第一个字符,以查看其是否符合给定的条件,在这种情况下是正则表达式。

$('input')。keyup(function(){ $ this = $(this); if this.val()。length == 1) { var x = new RegExp([\x00-\x80] +); // is ascii // alert(x.test($ this.val())); var isAscii = x.test($ this.val()); if(isAscii) { $ this.css(direction,ltr); } else { $ this.css (direction,rtl); } } });

这是一个使用 ltr ascii文本的方向和 rtl 。

这是一个工作示例。

When you go to Facebook and want to leave a comment, regarding which language you have chosen for your keyboard the direction of the textbox changes automatically when you click on it to write your comment. If you have chosen Arabic language for your keyboard the textbox automatically gets RTL direction. any idea how it has been implemented? I would like to use it on my web application.

thank you very much for your help, I really appreciate it.

regards

解决方案

You can use the CSS direction property to achieve this:

input{ direction: rtl; }

Update

To change the direction of the text dynamically based on the user input you can check the first character of input to see if it meets a given criteria, in this case a regular expression.

$('input').keyup(function(){ $this = $(this); if($this.val().length == 1) { var x = new RegExp("[\x00-\x80]+"); // is ascii //alert(x.test($this.val())); var isAscii = x.test($this.val()); if(isAscii) { $this.css("direction", "ltr"); } else { $this.css("direction", "rtl"); } } });

This is a basic example that uses ltr direction for ascii text and rtl for everything else.

Here's a working example.

更多推荐

自动更改文本框的文本方向

本文发布于:2023-11-03 16:05:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   文本   方向

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!