我试图在单击链接时显示并隐藏div。我得到了正确显示的div,但我希望该div可以消失,当我点击另一个。这是我目前的代码。单击链接时显示/隐藏div
<script type="text/javascript">
$(function() {
$('#attach_silver').click(function() {
$('#sec_silver').show();
return false;
});
});
$(function() {
$('#attach_gold').click(function() {
$('#sec_gold').show();
return false;
});
});
$(function() {
$('#attach_platinum').click(function() {
$('#sec_platinum').show();
return false;
});
});
</script>
<a href="#" id="attach_silver">Silver</a>
<a href="#" id="attach_gold">Gold</a>
<a href="#" id="attach_platinum">Platinum</a>
<div id="sec_silver" style="display: none;">
Hello world!! Silver
</div>
<div id="sec_gold" style="display: none;">
Hello world!! Gold
</div>
<div id="sec_platinum" style="display: none;">
Hello world!! Platinum
</div>
,什么是阻止你正是这样做?另外,您实际上不需要三个'document.ready'事件处理程序,只需要一个,并将在'document.ready'上运行的所有代码放入该事件处理程序中。 – Jasper