如何使用Javascript检测元素的文本方向? [英] How to detect text direction of element using Javascript?
本文介绍了如何使用Javascript检测元素的文本方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Javascript检测HTML元素的文本方向的最佳方法是什么?我希望得到rtl或ltr。
What's the best way to detect the text direction of an html element using Javascript? I would expect to get either "rtl" or "ltr".
<div dir="ltr" id="foo">bar</div>
<div style="direction:ltr" id="baz">quux</div>
<div dir="ltr"><div id="jeez">whiz</div></div>
我会如何测试foo,baz或jeez方向? / p>
How would I test for the direction on "foo", "baz" or "jeez"?
推荐答案
的getComputedStyle
是在现代浏览器(IE9 +和其他物质)可用。
getComputedStyle
is available in modern browsers (IE9+ and the others).
getComputedStyle(document.getElementById('foo')).direction
在Mozilla开发者网络上引用getComputedStyle
这篇关于如何使用Javascript检测元素的文本方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文