我试图在遍历无序列表 () 时找到 css 显示值,但由于某种原因 FF 不显示此值。这是我到目前为止所拥有的:
var LIs = document.getElementById('ulABC').getElementsByTagName('li');
for (var i=0; i<LIs.length; i++) {
alert('the li display value is :'+LIs[i].style.display+':');
}
我得到的只是一个空白的回应。有什么想法吗?
最佳答案
LIs[i].style.display
的值完全反射(reflect)了 style
属性中的设置。它不反射(reflect)浏览器从样式表中获得的任何信息。要获取这些计算值,请使用 window.getComputedStyle()
.
This link显示了它们的 .css()
属性的 jQuery 实现,它正是这样做的。请注意,在 IE 9 以下的 IE 上,您需要使用名为 document.documentElement.currentStyle()
的方法,因此需要 if..else
子句。
关于javascript - 获取 li 元素的 css 显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13032807/