我有几个 JavaScript 库竞争z-index
至高无上,并希望通过z-index
除了对象类型之外没有任何其他属性来转储完整的元素列表。
运行以下命令只给了我一个要遍历的元素:
$('html').each(function () {
console.log($(this).css('z-index') + ': ' + $(this).constructor);
});
我该怎么做?
我有几个 JavaScript 库竞争z-index
至高无上,并希望通过z-index
除了对象类型之外没有任何其他属性来转储完整的元素列表。
运行以下命令只给了我一个要遍历的元素:
$('html').each(function () {
console.log($(this).css('z-index') + ': ' + $(this).constructor);
});
我该怎么做?
您现在正在遍历html
元素。您要做的是使用*
选择器选择所有元素:
$("*").each(function () {
...
像这样的东西应该工作:
$("*").each(function(k, v){
console.log(v.nodeName + " " + $(v).css("z-Index"));
})
这是一个解决方案,它在没有任何第三方框架的情况下读取计算的样式表:
var elems = document.querySelectorAll( '*' );
for( var i = 0, len = elems.length; i < len; i++ ) {
var style = window.getComputedStyle( elems[i] );
console.log( elems[i].nodeName, style.getPropertyValue( 'z-index' ) );
/* style['z-index'] will also work, but it is better to use the API if there is one, in case something get's changed */
}