【发布时间】:2015-05-10 21:01:27
【问题描述】:
JQuery 不适用于本地机器上的点击事件,但在 JSfiddle 上正确工作请参阅此链接JSFiddle。在下面的代码中,我试图隐藏和显示 div 的其余部分。以下代码在 jsfiddle 上运行良好,但在本地计算机上单击没有响应。请告诉我我哪里错了..
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$("#grid_content").on("click", ".toggle", function(evt) {
evt.preventDefault(); // Prevent window following #hash / jump
var more = $(this).text() === "Show More";
$(this).text(more ? "Show Less" : "Show More").prev(".restPart").slideToggle();
});
</script>
<style type="text/css">
.bucket {
width: 290px;
float: left;
margin: 0 0 48px 20px;
border: 1px solid #262626;
background: lightgray;
}
.restPart{
overflow:auto;
display:none; /* hide initially */
}
</style>
</head>
</body>
<section id="grid_content">
<div class="bucket">
<p>Visible part....</p>
<div class="restPart">
<p>Content...</p>
</div>
<a href="#" class="toggle">Show More</a>
</div>
<div class="bucket">
<p>Visible part....</p>
<div class="restPart">
<p>Content...</p>
</div>
<a href="#" class="toggle">Show More</a>
</div>
</section>
</body>
</html>
【问题讨论】:
标签: javascript jquery html css