자바스크립 질문

자바스크립 질문

QA

자바스크립 질문

본문

<!DOCTYPE html>
<html>
<head>
<p style="color : blue">이것은
<span style="color:red" id="span">문장입니다.
</span>
</p>
<form id="form">
<input type="text" name="s">
<input type="button" value="테스트" id="button>"
<hr>
</form>
<script>
var form = document.getElementByld("form");
var button = document. getElementByld("button");

document.body.addEventListener("Click", bodyF1, true);
document.body.addEventListener("Click", bodyF2, false);
form.onclick = formF;
button.addEventListner("Click", buttonF1, false);
button.addEventListner("Click", buttonF2, true);

function bodyF1() {
}
function bodyF2() {
}
function formF1() {
}
function buttonF1() {
}
function buttonF2() {
}
</script>
</body>
</html>

 

버튼을 클릭했을 때, 이벤트리스너 5개 함수(bodyF1, bodyF2, formF, buttonF1, buttonF2)들이 호출되는 순서가 어떻게 되나요??

이 질문에 댓글 쓰기 :

답변 2

전체 코드 자체가 지금 잘못되었습니다.

출력 순서를 보고싶다면


function bodyF1() {
console.log('bodyF1');
}
function bodyF2() {
console.log('bodyF2');
}
function formF1() {
console.log('formF1');
}
function buttonF1() {
console.log('buttonF1');
}
function buttonF2() {
console.log('buttonF2');
}

위와 같이 콘솔 로그를 찍어보시면 됩니다.

크롬 F12 개발자도구에서 콘솔 탭에서 순서대로 출력되실겁니다.

물론 현재 올려주신 샘플 코드는 구동되지않는 코드라 로그가 찍히지 않습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 936
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT