开发者

How to stop Javascript from changing my text input direction?

开发者 https://www.devze.com 2023-04-06 05:22 出处:网络
I\'m executing the following JavaScript code: document.write(\'ל\'); document.write(\' 0 1 2\'); where the first input is text from a right-to-left language (eg Hebrew or Arabic), and the output i

I'm executing the following JavaScript code:

document.write('ל');
document.write(' 0 1 2');

where the first input is text from a right-to-left language (eg Hebrew or Arabic), and the output is as follows:

ל 0 1 2

with subsequent writes being written right-to-left, until some input is received which is inherently left-to-right (e.g. Latin characters).

The output still appears left-aligned, and setting the css direction attribute to ltr before the second write doesn't fix the problem.

Any ideas where the problem lie开发者_开发问答s?


Use unicode-bidi and direction to style the text:

<div style="direction:rtl;">ל<span style="direction:ltr;unicode-bidi:bidi-override;">0 1 2</span></div>

The output:

http://jsfiddle.net/HX4mB/

Here's a link for more information: http://www.w3.org/TR/CSS2/visuren.html#direction

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号