따라서 두 개의 이벤트 ( change
및 focusout
)에 바인딩 된 하나의 콜백 함수가 있습니다. 그러나 우리가 상호 작용하는 요소가 checkbox
.
다음은 예제 코드입니다.
$(document).on('focusout change', '.selector', function() {
if ($(this).is(':checkbox')) {
// Do stuff and prevent the focusout to trigger. HOW???
}
doStuff(); // Action that applies to both cases, but needs to be limited at one execution only
});
위의 코드는 두 번 실행됩니다.
나는을 사용해 보았지만 .off
결국 focousout
핸들러를 완전히 죽이게 되는데, 나중에 체크 박스가 아닌 다른 요소에 필요할 것이다.
focusout
핸들러가 특정 요소에 대해 트리거 하는 것을 방지하는 방법은 무엇입니까 ?
당신이 원하는 것은
$(document).on('focusout change', '.selector', function(event) {
event
속성이있는 이벤트 객체이며 그 중 하나는입니다 type
. type
이제 focusout
또는 a로 인해 함수가 호출되었는지 확인하고 change
적절한 코드를 실행할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다