jQuery:基于不同div的div高度
我试图根据 jQuery 中父元素的高度来确定元素的高度,但收效甚微。我的代码如下:
$(document).ready(function() {
$('#nav li:hover ul li ul').height() = $('#nav li ul').height() - 5;
$('#nav li ul li ul').height() = $('#nav li ul').height() - 5;
});
有什么想法为什么这行不通吗?
I'm trying to make the height of an element based on the height of a parent element in jQuery with little success. My code is as follows:
$(document).ready(function() {
$('#nav li:hover ul li ul').height() = $('#nav li ul').height() - 5;
$('#nav li ul li ul').height() = $('#nav li ul').height() - 5;
});
Any ideas why this won't work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
.height
是一个函数,因此当您调用.height()
时,您无法为其赋值。在 jQuery 中,您可以通过将新高度作为参数传递给.height
函数来设置元素的高度。.height
is a function, so when you call.height()
, you can't assign a value to it. In jQuery you can set an element's height by passing in the new height as an argument to the.height
function.你用错了...
You're using it wrong...
如果要设置元素的高度,请将高度作为第一个参数传递给 jQuery 对象的
height
方法,如下所示。当您不向height
方法传递任何参数时,它会返回匹配元素集中第一个元素的高度。If you want to set the height of an element then pass the height as first argument to
height
method of jQuery object as shown below. When you don't pass any argument toheight
method it returns the height of the first element in the matched set of elements.