2011-04-28 3 views
2

jQuery로 클릭 확인을 바인딩하려고합니다 (JSF 페이지의 코드 정리). jQuery click() 이벤트 전에 MyFaces로 작성된 onclick 인라인 함수 (oamSubmitForm();)가 실행된다는 것을 알고 있습니다. 이전에 jQuery 클릭을 할 수 있습니까? 당신은 내기 가장 좋은 것JSF <h : commandLink> 또는 <h : commandButton> 액션이 수행되기 전에 jQuery click() 이벤트를 어떻게 실행할 수 있습니까?

jQuery(".commandButtonConfirmDelete").click(function() { 
    var answer = confirm('Confirm Delete?'); 
    return answer; 
}); 

<h:commandLink styleClass="commandButtonConfirmDelete" /> 
<h:commandButton styleClass="commandButtonConfirmDelete" /> 

답변

2

는 인라인 클릭 이벤트를 검색하고 저장을 삭제하고 당신이 원하는 결국 삭제 한 저장 기능을 부르는 않는 자신의 기능으로 덮어하는 것입니다. http://jsfiddle.net/C9HTp/1/

alert('bar')가 인라인 설정하고 alert('foo').click()를 통해 바인딩 - 나는

$(function() { 
    var node = $('.commandButtonConfirmDelete').get(0), 
     savedAction = node.onclick; 

    //Remove the inline handler (we'll call it manually in our new handler) 
    node.onclick = null; 

    $(node).click(function() { 
    //do something 

    //then call your inline action 
    savedAction(); 
    }); 
}); 

이 바이올린보기 ... 같은 것을 할 것입니다. 그러나 위에서 설명한 방법을 사용하면 경고가 'foo', 'bar'순으로 표시됩니다.

희망이 도움이됩니다.

0

ID로 작업 할 수있는 경우 click 이벤트에 client-ids를 사용할 수 있습니다.

jQuery("#formId:commandButtonConfirmDelete").click(function() { var answer = confirm('Confirm Delete?'); return answer; });
<h:commandButton id="commandButtonConfirmDelete" />

관련 문제