如何检测当前网页或元素方向(rtl/ltr)或javascript中的任何其他属性?

use*_*805 2 javascript right-to-left

我如何读取当前影响不一定是样式的元素的任何属性?一个这样的属性将是"dir".

Sta*_*ano 5

最近我有类似的问题,你可以使用window.getComputedStyleelement.currentStyle方法获取元素的属性:

    var elem = document.getElementById('test');
    if (window.getComputedStyle) { // all browsers
        cs = window.getComputedStyle(elem, null).getPropertyValue('direction');
    } else {
        cs = elem.currentStyle.direction; // IE5-8
    }
    alert(cs);
Run Code Online (Sandbox Code Playgroud)

jsfiddle ; 兼容性信息