我正在使用$(this).find("ul").filter(":first").height();
获取第一个ul。
但是高度没有定义,那么高度是-20
我的ul:
ul style="width: 252px; min-width: 820px; padding-bottom: 20px;" class="jqx-tree-dropdown-root"
诚挚的问候。
发布于 2016-08-08 14:14:26
我创建了一个快速的jsFiddle,它很好地显示了您的代码应该工作得很好。然而,您可能错误地使用了"this“:)
https://jsfiddle.net/qoxub22u/
Html模型
<div class="container">
<h5>First one has height of 40px</h5>
<ul style="height:40px">
<li>Test</li>
<li>Test1</li>
</ul>
<h5>Second one has height of 70px</h5>
<ul style="height:70px">
<li>Test</li>
<li>Test1</li>
<li>Test2</li>
<li>Test3</li>
</ul>
</div>
<button id="submit">Get height</button>
Jquery部件
$( "#submit" ).click(function() {
/* Replace .container with ur this selector */
var height = $('.container').find("ul").filter(":first").height();
alert(height);
});
发布于 2016-08-08 14:33:37
$(this)是一个div。
$(this)相同:
var self =$(此);alert(self.find("ul").filter(":first").height());
未定义UL高度。
https://stackoverflow.com/questions/38830882
复制相似问题