라라리라

2023.09.07 / Step 3 [DOM_이벤트] - 코딩 47 일차 본문

코딩/2023 JavaScript DOM

2023.09.07 / Step 3 [DOM_이벤트] - 코딩 47 일차

헤실 2023. 9. 7. 22:38

_0319_mouse1.html

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>onclick</title>
</head>
<body>
    <style>
        #my_div {
            background: green;
            height: 300px;
            width: 1000px;
            display: block;
            margin: 0 auto;
        }
    </style>

    <div id="my_div">
    </div>
    <input id="clearbtn" type="button" value="clear" >
    <div id="result">
    </div>

    <script>
        let div = document.getElementById("my_div");
        let clearbtn = document.getElementById("clearbtn");
        let result = document.getElementById("result");

        div.addEventListener("click", (a) => {
            result.innerHTML+= "<div>click</div>";
        });

        div.addEventListener("mousedown", (a) => {
            result.innerHTML+= "<div>mousedown</div>"  + " x : " + a.pageX + " y : " + a.pageY;
        });

        div.addEventListener("mouseup", (a) => {
            result.innerHTML+= "<div>mouseup</div>"  + " x : " + a.pageX + " y : " + a.pageY;
        });

        clearbtn.addEventListener("click", (a) => {
            result.innerHTML= "";
        });
    </script>
</body>

</html>

 

onclick

 


_0319_mouse2.html

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>onclick</title>
</head>
<body>
    <style>
        #my_div {
            background: blue;
            height: 300px;
            width: 1000px;
        }
    </style>

    <div id="my_div">
    </div>
    <input id="clearbtn" type="button" value="clear" />
    <div id="result">
    </div>

    <script>
        let div = document.getElementById("my_div");
        let clearbtn = document.getElementById("clearbtn");
        let result = document.getElementById("result");

        div.addEventListener("mouseover", (event) => {
            result.innerHTML+= "<div>mouseover</div>";
        });

        div.addEventListener("mouseout", (event) => {
            result.innerHTML+= "<div>mouseout</div>";
        });

        clearbtn.addEventListener("click", (event) => {
            result.innerHTML= "";
        });
    </script>
</body>

</html>

 

onclick

 


_0319_mouse3.html

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>onclick</title>
</head>
<body>
    <style>
        #my_div {
            background: red;
            height: 300px;
            width: 1000px;
        }
    </style>

    <div id="my_div">
    </div>
    <input id="clearbtn" type="button" value="clear" />
    <div id="result">
    </div>

    <script type="text/javascript">
        let div = document.getElementById("my_div");
        let clearbtn = document.getElementById("clearbtn");
        let result = document.getElementById("result");

        div.addEventListener("mouseenter", (event) => {
            result.innerHTML+= "<div>mouseenter</div>";
        });

        div.addEventListener("mouseleave", (event) => {
            result.innerHTML+= "<div>mouseleave</div>";
        });

        clearbtn.addEventListener("click", (event) => {
            result.innerHTML= "";
        });

    </script>
</body>

</html>

 

onclick

 


_0319_mouse4.html

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>onclick</title>
</head>
<body>
    <style>
        #out_div {
            background: green;
            height: 400px;
            width: 400px;
            display: table-cell;
            text-align: center;
            vertical-align: middle;
        }

        #in_div {
            background: yellow;
            height: 100px;
            width: 100px;
            display: inline-block;
        }
    </style>

    <div id="out_div">
        <div id="in_div"></div>
    </div>
   
    <input id="clearbtn" type="button" value="clear" />
        <div id="result">
    </div>

    <script>
        let div = document.getElementById("out_div");
        let clearbtn = document.getElementById("clearbtn");
        let result = document.getElementById("result");

        div.addEventListener("mouseover", (event) => {
            result.innerHTML+= `<div>mouseover ${event.target.id}</div>`;
        });

        div.addEventListener("mouseout", (event) => {
            result.innerHTML+= `<div>mouseout ${event.target.id}</div>`;
        });

        clearbtn.addEventListener("click", (event) => {
            result.innerHTML= "";
        });


    </script>
</body>

</html>

 

onclick

 


_0319_onkeydown2.html

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   
</head>
<body>
    <h1>keydown</h1>
   <script>
        window.addEventListener("keydown", (e) => {  
            console.log(e.code); // 콘솔창 열어서 확인하기
        });
   </script>

</body>
</html>

 

Document

keydown

 


_0319_onkeyup3.html

 

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   
</head>
<body>
    <h1>keyup</h1>
   <script>

        window.addEventListener("keyup", (e) => {  
            console.log(e.code); // 콘솔창 열어서 확인하기
        });
   </script>

</body>
</html>

 

Document

keyup