오락기/js
add eventListener
문방구앞오락기
2017. 4. 18. 15:15
<body>
<input type="button" id="target" value="button" />
<script>
var t = document.getElementById('target');
t.addEventListener('click', function(event){ //function 이하부분이 clikc이라는 이름의 이벤트로 t라는객체에 들어감
alert('Hello world, '+event.target.value); //event.target.value 가 결국 buttion 이된다.
});
</script>
</body>