为什么jQuery的height()会自动舍入该值?

时间:2014-02-14 11:06:30

标签: jquery

我想计算列表的计算高度。在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/

1 个答案:

答案 0 :(得分:3)

这是jQuery中的一个已知错误,它不应该舍入高度和宽度值。

http://bugs.jquery.com/ticket/9628

更新了@ CookieMonster的评论

目前的解决方法是使用.getBoundingClientRect().height,它是跨浏览器,不会舍入值。

document.getElementById("fruits").getBoundingClientRect().height
相关问题