【发布时间】:2017-07-18 23:29:50
【问题描述】:
所以我在理解 JQuery 以及如何执行“显示更多”功能时遇到了一些麻烦。这是我正在工作的 HTML 文件,来自 Murach JQuery Book
<main id="jdom">
<h1>Murach's JavaScript and DOM Scripting</h1>
<h2>Book description</h2>
<div>
<p>You can read other JavaScript books from start to finish and still not
know how to develop dynamic websites like you want to. That's because
it's DOM scripting that lets you do things like run slide shows, handle image
rollovers, rotate headlines, provide animation, and more. And it's a subject
that's glossed over or ignored in most other books.</p>
</div>
<div class="hide">
<p>But now, you can go from JavaScript beginner to DOM scripting expert in a
single book! Fast-paced, professional, and packed with expert practices, our
new JavaScript book guides you through each step as you learn how to program
sites that enhance the user experience and ensure browser compatibility.</p>
</div>
<a href="#">Show more</a>
这是我正在使用的 Jquery
$(document).ready(function() {
$("a").click(function() {
$(this).toggleClass("hide");
if ($(this).attr("class") != "hide") {
$(this).next().hide();
}
else {
$(this).next().show();
}
});
});
所以我在发现代码中的错误时遇到了一些麻烦。如果我错误地将类隐藏到 classToggle 方法中。任何能帮助我更深入地了解我哪里出错的帮助将不胜感激!
【问题讨论】:
-
您想在点击查看更多时显示
.hide类文本? -
这就是我的目标