2013-10-03 2 views
2

팝업 외부에서 클릭하여 부트 스트랩 팝업을 해제하는 방법. 현재 오픈 링크를 토글하고 있습니다.외부에서 클릭하여 부트 스트랩 팝업을 닫습니다.

HTML

다음
<div class="widget-rating"> 
      <span class="rateit rating-average"></span> 
      <a class="btn btn-mini" href="javascript:void(0)"><b class="caret"></b></a> 
</div> 

은 JS 코드를입니다

element.popoverAnchor.popover({ 
     title: "Rating", 
     animation: false, 
     html: true, 
     content: "Loading...", 
     placement: "bottom", 
     trigger: "click" 
     }); 

답변

5
$('body').on('click', function (e) { 
    $('.popover-link').each(function() { 
     //the 'is' for buttons that trigger popups 
     //the 'has' for icons within a button that triggers a popup 
     if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { 
      $(this).popover('hide'); 
     } 
    }); 
}); 

참조 : 어떤 경우 .. 트리거 클래스를 지정할 필요가 없습니다에 대한 http://mattlockyer.com/2013/04/08/close-a-twitter-bootstrap-popover-when-clicking-outside/

+0

내 경우에는이 작동하지 않음 – Sowmya

+0

무엇이 오류입니까 ?? didnt는 일한다? –

+0

오류가없고 동시에 아무 작업도 수행하지 않습니다 – Sowmya

0
$('body').on('click', function (e) { 
    $("div.popover").each(function() { 
     if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { 
      $(this).prevAll('*:first').popover('hide'); 
     } 
    }); 
}); 

보편적 수정 요소

관련 문제