我试图在遍历无序列表()时找到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+':');
}
我得到的只是一个空白的回复。有什么想法吗?
我试图在遍历无序列表()时找到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中设置的值完全相同style。它不反映浏览器从样式表中得到的任何东西。要获取这些计算值,请使用window.getComputedStyle().
这个链接.css()显示了他们的属性的 jQuery 实现,它就是这样做的。请注意,在 IE 9 以下的 IE 上,您需要使用名为 的方法document.documentElement.currentStyle(),因此需要使用该if..else子句。
如果显示没有被显式设置为内联或使用 javascript,则需要使用 getComputedStyle()。它不会从样式表中获取任何内容。