<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<button type="button" onclick="alert('안녕하세요')">함수호출-직접 이벤트 호출</button>
<br><br>
<button type="button" onclick="hello()">자바스크립트 사용자 함수호출</button><br><br> //이 방법을 제일 많이 씀
<button type="button" id="btn3">이벤트를 자바스크립트로</button>
<script type="text/javascript">
function hello() {
alert("두번째 버튼을 클릭함_JavaScript 함수호출")
}
//버튼3에 이벤트추가
var b=document.getElementById("btn3");
b.onclick=function()
{
alert("3번째 버튼 클릭")
}
</script>
</body>
</html>



'JavaScript' 카테고리의 다른 글
| 210923_Event+confirm (0) | 2021.09.23 |
|---|---|
| 210923_event (0) | 2021.09.23 |
| 210923_getElementById,window.onload (0) | 2021.09.23 |
| 210923_document.body (0) | 2021.09.23 |
| 210923_list+inner (0) | 2021.09.23 |