我正在通过阅读这本书来学习 jQuery(顺便说一句,这本书非常好。)
当我进行教程 5 练习时,我注意到 jQuery 总是使用 jquery-1.9.0 自动设置为 display:none。当我更改为较低版本(例如 1.8.3 或 1.6.3)时,它们似乎运行良好。想知道您是否遇到过同样的问题?你用 1.9.0 版解决了吗?
下面是我的代码。您也可以从 ( http://sawmac.com/js2e/Chapter 5/complete_faq.html)下载它
<html>
<head>
<meta charset="UTF-8">
<title>A One Page Faq</title>
<link href="../_css/site.css" rel="stylesheet">
<style type="text/css">
h2
{
background: url(../_images/open.png) no-repeat 0 11px;
padding: 10px 0 0 25px;
cursor: pointer;
}
h2.close
{
background-image: url(../_images/close.png);
}
.answer
{
margin-left: 25px;
}
</style>
<script src="jquery-1.9.0.js"></script>
<script>
$(document).ready(function () {
$('.answer').hide();
$('.main h2').toggle(
function () {
$(this).next('.answer').slideDown();
$(this).addClass('close');
},
function () {
$(this).next('.answer').fadeOut();
$(this).removeClass('close');
}
); // end toggle
}); // end ready
</script>
</head>
<body>
<div class="wrapper">
<div class="header">
<p class="logo">JavaScript <i>&</i> jQuery <i class="mm">The<br>
Missing<br>
Manual</i></p>
</div>
<div class="content">
<div class="main">
<h1>A One Page FAQ</h1>
<h2>I've heard that JavaScript is the long-lost fountain of youth. Is this true?</h2>
<div class="answer">
<p>Why, yes it is! Studies prove that learning JavaScript freshens the mind and extends life span by several hundred years. (Note: some scientists disagree with these claims.)</p>
</div>
<h2>Can JavaScript really solve all of my problems?</h2>
<div class="answer">
<p>Why, yes it can! It's the most versatile programming language ever created and is trained to provide financial management advice, life-saving CPR, and even to take care of household pets.</p>
</div>
<h2>Is there nothing JavaScript <em>can’t</em> do?</h2>
<div class="answer">
<p>Why, no there isn’t! It’s even able to write its own public relations-oriented Frequently Asked Questions pages. Now that’s one smart programming language!</p>
</div>
</div>
<div class="footer">
<p>JavaScript & jQuery: The Missing Manual, by <a href="http://sawmac.com/">David McFarland</a>. Published by <a href="http://oreilly.com/">O'Reilly Media, Inc</a>.</p>
</div>
</div>
</div>
</body>
</html>