为什么jQuery的height()会自动舍入该值?
我想计算列表的计算高度。 在IE上,这两个给出了不同的结果。 在Chrome上,值似乎总是在整数上,所以我没有遇到这个问题。
// gives a string of "353.7px" window.getComputedStyle(mylist, null).getPropertyValue("height") // gives an int of 354 $(mylist).height();
为什么jQuery会丢弃小数,或者这是IE的问题?
编辑我实际上在说谎。 这种情况发生在Chrome上。 见http://jsfiddle.net/jTPk9/
这是jQuery中的一个已知错误,它不应该舍入高度和宽度值。
http://bugs.jquery.com/ticket/9628
更新了@ CookieMonster的评论
当前的解决方法是使用.getBoundingClientRect().height
,它是跨浏览器并且不会舍入值。
document.getElementById("fruits").getBoundingClientRect().height