2012-09-08 36 views
0

嘿,大家我再次有腳本問題。我正在爲post中的成員個人資料數據做一個jQuery顯示/隱藏。請訪問http://www.pimpkings.com/t3-what-up-everyone查看我在說什麼,我將代碼保留下來,以便您可以看到它在做什麼。jquery隱藏/顯示搞砸

每當我點擊一個人顯示/隱藏它打開每個人,我只希望它打開1人在用戶請求。

代碼爲─

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$(".slidingDiv").hide(); 
$(".show_hide").show(); 
    $('.show_hide').click(function(){ 

$(".slidingDiv").slideToggle(); 

}); 

}); 
</script> 

然後將HTML編碼是

<span class="show_hide" style="cursor:pointer;color:#c0c0c0;">Show/hide</span> 
<div class="slidingDiv"> 
           <!-- BEGIN profile_field --> 
          <center> {postrow.displayed.profile_field.LABEL} <center/> 
          <center> {postrow.displayed.profile_field.CONTENT} <center/> 
          <center> {postrow.displayed.profile_field.SEPARATOR}<center/> 
          <!-- END profile_field --> 
          <center>{postrow.displayed.profile_field.LABEL}<center/> 
          <center>Online Status<center/><br/> 
          <center>{postrow.displayed.ONLINE_IMG}<center/> 
             {postrow.displayed.POSTER_RPG} <br /> 

          <!-- BEGIN contact_field --> 
          <br/> <br/> 
          {postrow.displayed.PROFILE_IMG} {postrow.displayed.PM_IMG} 
          {postrow.displayed.EMAIL_IMG} {postrow.displayed.contact_field.CONTENT} 
          <!-- END contact_field --> 
           <span class="show_hide" style="cursor:pointer;color:#c0c0c0;">hide</span></div> 
          </span> 

誰能幫助找出另一種選擇,因此不會立刻打開所有?

回答

0

試試這個:

$(document).ready(function() { 
    $(".slidingDiv").hide(); 
    $(".show_hide").show(); 
    $('.show_hide').click(function() { 
     $(this).next(".slidingDiv").slideToggle(); 
    }); 
});​ 

請注意,你應該在配置文件到別的東西年底改變「隱藏」鏈接的類(如只是隱藏),這樣就可以更容易地對其進行定位用jQuery來隱藏配置文件。

哦,還有一件事,<center>標籤很久以前就被棄用了。改用CSS來居中。

jsFiddle example

+0

哈哈

這是過時哇,顯示了多久它以來的Ive編程。我12歲時開始學習,當時html有一半已棄用的元素。在創建這些語言的一半之前的方式。我會試試看,並讓你知道謝謝 –

+0

謝謝你,它的工作原理。我會喜歡這個,但不能。你能否解釋一下這種奇妙的運作方式?是$(this).next是什麼創建它來一次打開一個? –

+0

是的,這是指被點擊的元素,所以其他代碼是相對於該特定元素而不是具有某個類的所有元素。 – j08691