2014-02-24 2 views
0

jQuery "맥동"효과를 사용할 때 대상 div에 링크가 있으면 링크가 작동하지 않습니다. 슬라이더 효과가 실행되는 것을 어떻게 방지 할 수 있습니까? 대신 링크를 클릭하여 "펄스"div 안에있는 대상을로드 할 수 있습니까?링크가있는 JQuery 토글 링크

$(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/25sQs/

:

http://jsfiddle.net/7xb2V/

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

또는

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

당신은 또한 astopPropagation에 두 번째 처리기를 바인딩 할 수 있습니다 : 당신은 링크에 대한 것을 일을 방지 할 수 있습니다

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

감사합니다, 나는 그것이 작동하는 것과 관련이 있음을 알고있었습니다. 방금 자바 스크립트에서 코드를 작성하는 방법을 알지 못했습니다. – TrippedStackers