我如何读取当前影响不一定是样式的元素的任何属性?其中一个属性是“dir”。
最近我也遇到了类似的问题,你可以通过 window.getCompulatedStyle 和 element.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);
在 JavaScript 中也可以轻松获取变量:
var direction = document.dir;
如果是 rtl,则为“rtl”