2011-01-17 6 views
17

onblur, onmousedown, onmouseup 및 onfocus에 대해 다음 div가 있습니다. 코드를 최소화하고 모든 함수에 대해 div 내에서 한 함수 만 호출하려고합니다. 상태. 나는 jquery로 이것을하고 싶다. 나는 functionAll이라는 함수를 만들고, function1을 function 4에 넣고 싶습니다. 그 안에는 마우스 상태가 있고, div 안에 functionAll 만 사용하고 싶습니다. 이렇게하면 어떻게 할 수 있습니까?하나의 이벤트 핸들러를 jQuery로 여러 이벤트에 바인딩

<div contentEditable="true" 
    onblur="function1();" 
    onmousedown="return function2(event);" 
    onmouseup="function3();" 
    onfocus="function4();"> 
    test test 
</div> 
+1

이 왜 그렇게 할 것입니다 :

$('#test').bind('blur mousedown mouseup focus', function (e) { // This is your combined function // Inside here you can use e.type to find out whether it was a // "blur", "mousedown", "mouseup", etc... }); 

html로 모습 것인가? –

답변

47

당신은 DIV에 ID를 넣어해야하고, "테스트"라고 :

<div id="test" contentEditable="true"> 
    test test 
</div> 
+0

알 것. 감사. – Hussein

+1

@ Box9 여하튼 나는 문서에서 그것을 놓쳤다. 그것은 정확하게 내가 찾고 있었던 것이다. 감사! –

관련 문제