Menu



Manage

파일 목록
Study_Web > 이후/practice9-5.html Lines 36 | 1.2 KB
다운로드

                        <!DOCTYPE html>
<html lang="en" ondblclick="randomBackground()">

<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>자바스크립트 연습</title>
    <script>
        //        function randomBackground() {
        //            let r = Math.floor(Math.random() * 256); //0~255
        //            let g = Math.floor(Math.random() * 256);
        //            let b = Math.floor(Math.random() * 256);
        //
        //           document.body.sytle.backgroundColor = `rgb(${r}, ${g}, ${b})`;
        //        }

        window.ondblclick = function (e) {
            let r = Math.floor(Math.random() * 256); //0~255
            let g = Math.floor(Math.random() * 256);
            let b = Math.floor(Math.random() * 256);

            document.body.style.backgroundColor =
                `rgb(${r}, ${g}, ${b})`;
        }
    </script>

</head>

<body>
    <h3>바탕 아무 곳에나 더블 클릭</h3>
    <hr>
    <p>바탕 아무곳이나 <strong>더블클릭</strong>하시면 배경색이 랜덤하게 변경되요!</p>
</body>

</html>