我有三个充当按钮的图像。每个人都有相同的班级。当我单击图像时,我希望文本“Active”出现在其下方(在图像所在的 div 之外)。每个图像下的文本都是相同的,但是如果我单击另一个图像,我希望文本隐藏它一直显示的位置并显示在我刚刚单击的图像下。现在,我点击一张图片,“活动”出现在所有三张图片下方,我再次点击,所有三张都消失了。我哪里错了?
剧本:
<script type="text/javascript">
$(function()
{
$('p.active').hide();
});
$(function()
{
$('.mosaic-block').click(function(){
$('.mosaic-block').removeClass('mosaic-block-highlighted');
$(this).addClass('mosaic-block-highlighted');
$('p.active').show(showHide);
});
});
function showHide()
{
var id=$(this).attr("p");
if($(this).is(":visible"))
{
$(id).hide();
$(this).html("");
}
else
{
$(id).show();
$(this).html("ACTIVE");
}
return false;
};
</script>
的HTML:
<div class="imgBlock">
<div class="mosaic-block cover">
<div class="mosaic-overlay" style="display: block; left: 0px; bottom: 0px;">
<img type="image" src="/images/g_crop.jpg"/>
</div>
<a href="javascript:;" onclick="launchX3()" id="x3" class="mosaic-backdrop" style="display:inline;">
<div class="details">
<h1>G Demo</h1>
<h4>Select G</h4>
</div>
</a>
</div>
<img class="button" type="image" src="/images/g_btn.jpg"/>
<p class="active">ACTIVE</p>
</div>
<div class="imgBlock">
<div class="mosaic-block cover">
<div class="mosaic-overlay" style="display: block; left: 0px; bottom: 0px;">
<img type="image" src="/images/e_crop.jpg"/>
</div>
<a href="javascript:;" onclick="launchX2()" id="x2" class="mosaic-backdrop" style="display:inline;">
<div class="details">
<h1>E Demo</h1>
<h4>Select E</h4>
</div>
</a>
</div>
<img class="button" type="image" src="/images/e_btn.jpg"/>
<p class="active">ACTIVE</p>
</div>
<div class="imgBlock">
<div class="mosaic-block cover boxgridLast">
<div class="mosaic-overlay" style="display: block; left: 0px; bottom: 0px;">
<img type="image" src="/images/c_crop.jpg"/>
</div>
<a href="javascript:;" onclick="launchX1()" id="x1" class="mosaic-backdrop" style="display:inline;">
<div class="details">
<h1>C Demo</h1>
<h4>Select C</h4>
</div>
</a>
</div>
<img class="button" type="image" src="/images/c_btn.jpg"/>
<p class="active">ACTIVE</p>
</div>`