2014-02-24 99 views
0

當使用jQuery「pulsate」效果,並且目標div中存在鏈接時,鏈接無法運行。我怎樣才能防止滑塊效果運行,而是可以點擊一個鏈接,並加載目標,即在「pulsate」div內?JQuery Toggle with Link

這裏是一個代碼示例:

$(document).ready(function() { 
    $(".toggler").click(function (event) { 
     event.preventDefault(); 
     $(this).effect('pulsate',{times:2},function(){ 
      $(this).fadeOut('slow'); 
     }); 
    }); 
}); 


<div class="aeast toggler"> 
    <table class="" width="100%"> 
      <tr> 
      <th><img src="http://content.sportslogos.net/logos/7/151/thumbs/y71myf8mlwlk8lbgagh3fd5e0.gif" alt="Patriots"></th> 
      <th><img src="http://content.sportslogos.net/logos/7/152/thumbs/v7tehkwthrwefgounvi7znf5k.gif" alt="Jets"></th> 
      <th><img src="http://content.sportslogos.net/logos/7/150/thumbs/15041052013.gif" alt="Dolphins"></th> 
      <th><img src="http://content.sportslogos.net/logos/7/149/thumbs/n0fd1z6xmhigb0eej3323ebwq.gif" alt="Bills"></th> 
      </tr> 
      <tr> 
      <td class="name">New England Patriots</td> 
      <td>asdad</td> 
      <td>dasd</td> 
      <td>asd</td>        
      </tr> 
      <tr> 
      <td><a href="http://www.google.com" target="_blank">Main Website</a></td> 
      <td>asda</td> 
      <td>asda</td> 
      <td>asda</td>        
      </tr>      
    </table>      
</div> 

http://jsfiddle.net/zuE65/

回答

1

你防止你的點擊處理程序的默認操作。你能避免這樣做的鏈接:

http://jsfiddle.net/7xb2V/

if (event.target.tagName.toLower() == 'a') return; 

或者

if ($(event.target).is('a')) return; 

你可能還結合第二種處理程序的astopPropagation

http://jsfiddle.net/25sQs/

$('.toggler a').click(function(e) { 
    e.stopPropagation(); 
}); 
+0

謝謝你,我知道它與一個功能有關。我只是不知道如何去構建JavaScript中的代碼。 – TrippedStackers