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

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

问题描述

当我运行以下代码:

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

'。

推荐答案

也许你在$(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天全站免登陆