2013-06-27 2 views
0

질문 js에서 이벤트 처리기의 속성을 확인하는 방법은 무엇입니까?

<!DOCTYPE HTML> 
<html> 
<body> 
<style type="text/css"> 
#a {background-color:blue;width:100px;height:200px;} 
#b {background-color:red;margin-left:25px;width:50px;height:100px;} 
</style> 
<div id="a">a 
    <div id="b">b</div> 
</div> 
<script> 
document.getElementById("a").onclick = function() {console.log("A is clicked");} 
document.getElementById("b").onclick = function() {console.log("B is clicked");} 
document.onclick = function() {console.log("Document is clicked");} 
</script> 
</body> 
</html> 
: 위의 코드에 대한

, 그것은 바로, 그들은 또한 객체, 3 클릭 이벤트 처리기를 등록? 그렇다면 어떻게이 3 개의 핸들러/객체의 속성, 콘솔의 메소드를 확인할 수 있습니까?

+0

을 정확하게 무엇입니까 할/찾으려고? 이 경우 이벤트 핸들러는 단지 함수입니다. 다른 기능과 동일한 속성을가집니다. –

답변

1

당신은 단지에 기능을 할당하는

document.getElementById("a").onclick = function() {console.log("A is clicked");} 

onclick 재산을 고정 할 때, 그 앵커을 클릭 한 후 경우, 브라우저는 해당 기능을 실행됩니다. 이 기능이 무엇인지 읽으려면, 당신은 단지 난 정말 당신이 뭘 하려는지 모르겠어요 출력

console.log(document.getElementById("a").onclick); 
0

필요, 어쩌면이 당신을 도와줍니다 :

document.getElementById("a").onclick = function(event) { 
    console.log("A is clicked"); 
    console.log(this); //refers to the source element object 
    console.log(event); //refers to the event object 
} 
관련 문제