我有一些使用百分比定义height
的元素。当我试图将高度保存为一个变量以供使用时,它会以像素
或者有时候没有值的形式保存。
例如:
<div id='firstDiv'></div>
<div id='secondDiv'></div>
CSS代码
#firstDiv{
width:50%;
height:50%;
}
#secondDiv{
width:20%;
height:50%;
}
Jquery代码
$('div').each(function (){
console.log($(this)[0].style.height);
}
我该如何将它显示为%
?
$(this)[0]
可以直接替换为this
,是吗? - King King