我有一个页面有多个div,我想彼此独立打开和关闭。到目前为止我的代码是在这里:http://jsfiddle.net/Einulfr/q4ra0gbb/JQuery - 多个div独立打开/关闭
的Javascript:
$(document).ready(function() {
$("#hide").click(function() {
$("#show").show();
$(".expandedText").hide();
});
$("#show").click(function() {
$("#show").hide();
$(".expandedText").show();
});
});
HTML:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h2>Title of First Article</h2>
<p>Story introduction paragraph here...</p>
<a href="#" id="show">Read More...</a>
<div class="expandedText" style="display: none;>
<p>Story continued here in second paragraph...</p>
<p>Story continued here in third paragraph...</p> <a href="#" id="hide">Close Article</a>
</div>
<h2>Title of Second Article</h2>
<p>Story introduction paragraph here...</p>
<a href="#" id="show">Read More...</a>
<div class="expandedText" style="display: none;>
<p>Story continued here in second paragraph...</p>
<p>Story continued here in third paragraph...</p> <a href="#" id="hide">Close Article</a>
</div>
但正如你所看到的,而第一个工作正常,后续的div不和也开放和关闭第一个div的操作。 我也希望'Read More ...'在点击时消失,当我点击'Close Article'时返回...目前这种方法可行,但对类似问题的其他解决方案似乎只是在最初的阅读更多...)链接,并要求重新点击原始链接以再次隐藏它。我希望这是有道理的:/
我是一个完全新手,当谈到这种事情;我错过了什么/做错了什么?
非常感谢提前
ID是单数。 – epascarello
就像@epascarello提到的一样,一个元素ID应该是唯一的页面。 – Sid