2014-03-27 102 views
0

這可能看起來很簡單,但花了近5小時後我找不到。 我裏面<c:foreach>Jquery褪色問題

<a href="#" class="helpTip1" id="removeId"> 
         <span id="helptext1" class="help_txt1"> 
         <span class="help_txt1" id="helptxtContent"> 
           help text goes here       </span> 
      </span> 
      </a> 

以下HTML元素然後,我有以下的jQuery。

var hide = false; 
$(document).ready(function() { 

$("#removeId").click(function(){ 


    if(hide==true){ 
     $("#helptxt1").fadeIn('slow'); 
     $("#helptxtContent").fadeIn(function(){hide = false;}); 

    } 
    if(hide==false){ 
     $("#helptxt1").fadeOut('slow'); 
     $("#helptxtContent").fadeOut(function(){hide=true;}); 

    } 
}); 
}); 

的問題是隻有當我點擊第一個elelmetn與id=removeid的幫助文件越來越褪色。 當我點擊第二個元素(因爲它裏面的C:foreach),這個jquery不起作用。

請幫我一把。

+1

ID應該是唯一的,你需要使用類,而不是 –

+0

@LogicBurner:OP提及ID爲錨標記'removeid'將在第一個元素的情況下工作。 OP有一個與同一個ID爲'removeid'的錨點不起作用。 – Unknown

+0

我想要幫助文本淡出時點擊id id removeId –

回答

1

使用fadeToggle in jquery();

$("#removeId").click(function(){ 

     $("#helptxt1").fadeToggle('slow'); 
     $("#helptxtContent").fadeToggle('slow'); 

}); 
0

當你有多個重複的ID,點擊事件處理程序將只能用於與該ID的第一要素即#removeId

您需要使用類而不是ID的 -

<a href="#" class="helpTip1 removeId"> 
    <span class="help_txt1 helptext1"> 
     <span class="help_txt1 helptxtContent" > 
     help text goes here 
     </span> 
    </span> 
</a> 

的jQuery -

var hide = false; 
$(document).ready(function() { 
    $(".removeId").click(function() { 
     if (hide == true) { 
      $(".helptxt1",this).fadeIn('slow'); 
      $(".helptxtContent",this).fadeIn(function() { 
       hide = false; 
      }); 
     } 
     if (hide == false) { 
      $(".helptxt1",this).fadeOut('slow'); 
      $(".helptxtContent",this).fadeOut(function() { 
       hide = true; 
      }); 
     } 
    }); 
}); 

演示---->http://jsfiddle.net/4jUmL/