부모를 클릭하면 특정 자식에게 영향을 주어야합니다 (스타일 전환).
핸들러로 토글 기능을 달성했습니다.
$(".p1").on({
mouseenter: mouseEnter,
mouseleave: mouseLeave
});
function mouseEnter() {
$(this).css('border', 'solid 5px #999999');
}
function mouseLeave() {
$(this).css('border', 'solid transparent 5px');
}
function handler1() {
$(this).css('border', 'solid 5px #222222');
$(this).off('mouseenter mouseleave');
$(this).one("click", handler2);
}
function handler2() {
$(this).css('border', 'solid transparent 5px');
$(this).on({mouseenter: mouseEnter, mouseleave: mouseLeave});
$(this).one("click", handler1);
}
$(".p1a").parent(".p1").one("click", handler1);
$(".pl").children(".p1").one("click", handler1); //this one doesn't work
부모 (마지막 줄)를 클릭하여 자식에게 영향을주는 것을 제외하고는 모든 것이 작동합니다.
이 기능을이 기능에 어떻게 추가 할 수 있습니까?
다음은 최종 기능입니다 -http : //jsfiddle.net/2czxN/6/
자녀 (p1a) 또는 부모 (pl)를 클릭하더라도 100 % 정확하게 작동합니다.
$(".p1a").one("click", handler1);
$(".pl").one("click", handler1);
키는 모든 선택기 ( find
, parent
)를 $(this)
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다