[英]jQuery .height() property not working
I'm attempting to get the height of an element using jQuery, but am receiving some unexpected results. 我试图使用jQuery获取元素的高度,但是我收到了一些意想不到的结果。 Here's the code:
这是代码:
$(function() {
var contentheight = $('#subpage-content-small').height;
alert(contentheight);
});
Where #subpage-content-small has these CSS properties: #subpage-content-small具有以下CSS属性:
#subpage-content-small { width: 400px; float: left; margin: 30px 10px 0 0; padding-bottom: 45px; }
What I'm getting as an output for my alert is the following: 我作为警报的输出得到的是以下内容:
function (f) { var e = this[0]; if (!e) { return f == null ? null : this; } if (c.isFunction(f)) { return this.each(function (j) {var i = c(this);i[d](f.call(this, j, i[d]()));}); } return "scrollTo" in e && e.document ? e.document.compatMode === "CSS1Compat" && e.document.documentElement["client" + b] || e.document.body["client" + b] : e.nodeType === 9 ? Math.max(e.documentElement["client" + b], e.body["scroll" + b], e.documentElement["scroll" + b], e.body["offset" + b], e.documentElement["offset" + b]) : f === w ? c.css(e, d) : this.css(d, typeof f === "string" ? f : f + "px"); }
Any idea why I'm getting this as opposed to an integer of the height? 知道为什么我得到这个而不是高度的整数? Thanks in advance!
提前致谢!
var contentheight = $('#subpage-content-small').height();
这是一种功能,而不是财产。
From jquery: 来自jquery:
The difference between .css('height') and .height() is that the latter returns a unit-less pixel value (for example, 400) while the former returns a value with units intact (for example, 400px).
.css('height')和.height()之间的区别在于后者返回无单位像素值(例如,400),而前者返回单位完整的值(例如,400px)。 The .height() method is recommended when an element's height needs to be used in a mathematical calculation.
当需要在数学计算中使用元素的高度时,建议使用.height()方法。
Try calling it as height()
instead of height
尝试将其称为
height()
而不是height
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.