본문 바로가기

카테고리 없음

html, css, javascript 종합으로 만든 페이지 배경색이랑 폰트색 원하는대로 바꾸는 거 [web]

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body id="im">
    <form>
        <input type="text" name="colour">
        <!-- <input type="submit"> -->
        <br>
        <input type="text" name="fon">
        <input type="submit">
        <!-- <button type="button" onclick="print()">출력</button> -->
    </form>
    <script>
        //왜 안 되지
        // var b = document.getElementById("im");
        // b.addEventListener("keypress", abc);
        // function abc(e) {
        //     console.log(e);
        //     if (e.key == "Space") {
        //         alert(e.key);
        //     }
        // }
        var a = new URLSearchParams(location.search).get("colour");
        // var a = "white";
        // function print() {
            //     a = new URLSearchParams(location.search).get("colour");
            //     // document.write(typeof(a));
            // }
            // document.write(typeof(a));
            // document.write(a);
        document.body.style.backgroundColor = a;
        document.getElementById("im").style.color = new URLSearchParams(location.search).get("fon");
        document.write(new URLSearchParams(location.search).get("fon"));
    </script>
</body>
</html>