.css('width')和.css('height')与.width()和.height() [英] .css(‘width’) and .css(‘height’) versus .width() and .height()

查看:79
本文介绍了.css('width')和.css('height')与.width()和.height()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我一直在问,没有人能真正告诉我使用.css(‘width’).css(‘height’)而不是.width().height()的好处.

Guys I've been asking around and nobody can really tell me the benefits of using .css(‘width’) and .css(‘height’) rather than .width() and .height().

我知道它们都返回偏移尺寸,这是元素的真实尺寸,无论其内部内容如何拉伸.

I know that they both return the offset dimensions, which are the genuine dimensions of the element no matter how stretched it is by its inner content.

我猜想有些事情是可以做的,而另一件事是不能做的,因为我使用css()返回窗口和文档的尺寸,其中FF这样做没有问题,但是IE抛出了一个问题.对我的错误.因此,我猜测它们可能在某些浏览器中工作,而在其他浏览器中工作.因此,我是否必须将两者结合使用以实现100%跨浏览器兼容性,或者仅在某些情况下使用?

I'm guessing that there are some things that one can do and the other one cannot as I was using css() to return the dimensions of a window and document, where FF had no issues doing this but IE threw back an error at me. So I'm guessing that they might work in some browsers and but others. So would I have to use both together for 100% cross browser compatibility or just for certain cases?

推荐答案

var elH = someElement.height();           // 200

.height()返回数字,而

var elH = someElement.css("height");      // "200px"

jQuery上方的jQuery会像JS那样访问元素的style属性:

above jQuery accesses the element's style property like JS would in:

var height = someDOMelement.style.height; // "200px"

返回px中的 String 值.

这篇关于.css('width')和.css('height')与.width()和.height()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆