2012-05-24 2 views
1

동일한 div에 마우스 오버 기능과 onclik 기능을 모두 연결하는 올바른 방법은 무엇입니까?동일한 div에 마우스를 올리고 기능을 클릭하십시오.

$(function outlineHider(){ 
    $("#hotspot").hover(
     function() { 
      $("#outlines").show(); //showing another div element 
      function bindClick() { 
       $("#hotspot").click(callAnotherFunction())}; 
      }, 
      function() { 
       $("#outlines").hide(); 
      } 
     ); 
}); 
+2

가능 중복 -. http://stackoverflow.com/questions/2432003/combine-hover-and-click-functions-jquery – Neil

답변

2

이 시도 :

$(function() { // document ready handler shortcut 
    $("#hotspot").hover(
     function() { $("#outlines").show(); }, 
     function() { $("#outlines").hide(); } 
    ).click(function() { 
     callAnotherFunction() 
    }); 
}); 

또는 짧은 버전을 @VisioN 덕분에 : 여기

는 (클릭은 아무것도하지 않는다) 내가 시도했지만 작동하지 않았다 무엇

$(function() { 
    $("#hotspot") 
     .hover(function() { $("#outlines").toggle(); }) 
     .click(callAnotherFunction);  
}); 
+1

'$ ("# 핫스팟") 마우스를 (함수() {$ (" #outlines ") .toggle();})'도 작동해야하지만 더 짧아야합니다. – VisioN

+0

위대한 작품, 대단히 감사합니다! –

+0

문제 없으니 기꺼이 도와주세요. –

0

내가 맞으면이게 도움이 될 것입니다.

$(function outlineHider(){ 
    $("#hotspot").hover(
     function() { 
      $("#outlines").show(); //showing another div element 
    }),click(function(){ 
     $("#outlines").hide(); 
    }); 
}); 

Combine hover and click functions (jQuery)?

var에 hoverOrClick = 함수() { // 일반적인 뭔가 할} $ ('# 목표를') (hoverOrClick) .hover (hoverOrClick)를 클릭합니다.;

두 번째 방법 : 사용 바인딩 :.

$ ('# 대상') 바인드 ('호버를 클릭'기능() { // 모두 뭔가를 수행});

관련 문제