2014-02-23 6 views
1

asp 메뉴에서 C# click 이벤트를 발생시키는 간단한 javascript mouseover 이벤트가 있습니다. 정상적으로 작동하지만 menuitem을 입력하면 click 이벤트가 무한정 발생합니다. 한 번만 발사하길 바래.한 번의 클릭으로 mouseover

<script type="text/javascript"> 
$(".div1").mouseover(function() { 
    $(this).click(); 
}) 
.mouseleave(function() { 
    $("#Menu1").remove(); 
    $("#Menu2").remove(); 
    $("#Menu3").remove(); 
}); 
</script> 

답변

2

두 가지 방법으로이 작업을 수행 할 수 있습니다

첫 번째 방법 :

$(".div1").mouseover(function() { 
    $(this) 
     .click() 
     .off('mouseover'); // Unbind the mouseover once we triggered the click 
}) 

두 번째 방법 - "사실 말이다"을 사용하여 한 번만

$(".div1").one('mouseover', function() { 
    $(this).click(); 
}) 
을 처리하는 이벤트를 트리거하는 바인딩
+0

그들은 모두 작동하지 않습니다. – Amr

+0

작동해야합니다. 더 자세한 코드를 제공하거나 문제 자체를 표시하는 jsFiddle을 더 잘 제공해야합니다. –

+0

jsFiddle에서 C# click 이벤트를 작성할 수 없습니다. 가능한 경우조차 알지 못합니다.하지만 jQuery 호출이 문제인지 확실히 알고 있습니다. – Amr

0

시도해 볼 수 있습니다.

,
0

사용 unbind jQuery의 기능 :

var fireClick = function() { 
    $(this).click(); 
    $(this).unbind('mouseover'); 
}; 

$(".div1").mouseover(fireClick) 
.mouseleave(function() { 
    $("#Menu1").remove(); 
    $("#Menu2").remove(); 
    $("#Menu3").remove(); 
    $(this).mouseover(fireClick); 
}); 
관련 문제