2010-12-15 57 views
0
<html> 
<head> 
<style type="text/css"> 
div.panel 
{ 
height:20px; 
display:none;} 

</style> 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $("img").click(function(){ 
    $(".panel").toggle(); 
    }); 
}); 
</script> 

</head> 
<body> 

<TABLE border="1"> 
<TR> 
<TD>to see whats hidden under here press to image</TD> 
<TD>IMG SRC=".jpg" WIDTH="20" HEIGHT="20" BORDER="0" ALT=""</TD> 
</TR> 
</TABLE> 
<div class="panel"><p>Haa haa, nothin</p></div> 

<TABLE border="1"> 
<TR> 
<TD>wanna see what under here?</TD> 
<TD>IMG SRC=".jpg" WIDTH="20" HEIGHT="20" BORDER="0" ALT=""</TD> 
</TR> 
</TABLE> 
<div class="panel"><p>treasure from bottom of ocean</p></div> 

</body> 
</html> 

Porblem是,當我按第一或第二圖像,我看到第一件事隱藏和第二件事隱藏。我想這樣做,當我按下第一張圖片時,我只能看到隱藏在那裏的內容,並且我可以切換它,而不僅僅是顯示並且再也不會隱藏。如何在我需要的所有位置上使用相同的腳本?

+0

'$(「板」)'的意思是「有'panel'在其CSS類你需要將它縮小來接你感興趣的特定面板的一切。 ,因此sje397中最接近('table')。next(「。panel」)' – 2010-12-15 04:51:35

回答

3

嘗試:

$(document).ready(function(){ 
    $("img").click(function(){ 
    $(this).closest('table').next(".panel").toggle(); 
    }); 
}); 
+0

謝謝,效果很好 – Noobert 2010-12-15 05:21:35

相關問題