jQuery:为什么CSS(' width')返回的值与width()不同 [英] jquery: why css('width') returns different value than width()

查看:72
本文介绍了jQuery:为什么CSS(' width')返回的值与width()不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下代码时:

        node = $('.period')
        alert(node.width() + ' ' + node.css('width'))

我得到"0 144px".那怎么可能?

i get '0 144px'. How is that possible?

推荐答案

也许您是在$(document).ready上调用它的,并以 width() 的形式获取当前计算的,像素,第一个匹配元素的宽度.,由于尚未渲染,因此为0 ...
css('width')但是从css样式表中读取,该样式表已经可用.

Maybe you're calling it on $(document).ready, and as width() Gets the current computed, pixel, width of the first matched element., it'd be 0 as it has not been rendered yet...
css('width') however reads from the css stylesheet, which would be already available.

这篇关于jQuery:为什么CSS(' width')返回的值与width()不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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