【发布时间】:2011-07-01 14:04:38
【问题描述】:
我曾经能够掌握
$('[data-role=header]').first().height()
在 jQuery 1.5.2 的 alpha 版本中,但不再可以在 jQuery 1.6.1 的 beta 版本中。有什么变化吗?
完整代码 - 这会将 0 写入 console.log...
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript"
src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
console.log($('[data-role=header]').first().height());
});
</script>
</head>
<body>
<div data-role="page" id="home">
<div data-role="header">
<h1>Header</h1>
</div>
<div data-role="content">
//lots of code
</div>
</div>
</body>
</html>
但是,将其更改为 jQuery 1.5.2 和 jQuery Mobile alpha:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"></script>
它会写入标题 div 的非零高度。
顺便说一句,在 jQuery 1.6.1 但没有 jQuery Mobile 时它也是非零的。所以这与 jQuery Mobile 渲染有关。
在release notes 中看不到任何提示可能发生的事情,但我不是 jQuery 专家。
【问题讨论】:
-
它在 Alpha/Beta 中写了什么,或者你期望它写什么?
-
在 alpha 中它会写一些非零的东西,因为 div 的高度是非零的。在测试版中它为零。顺便说一句,使用 jQuery 1.6.1 但 没有 jQuery Mobile 它也非零(已编辑问题以反映这一点)。
-
你可以试试这个:$('[data-role="header"]').first().height()
标签: javascript jquery jquery-mobile