JS DOM 실습2

tpids·2024년 6월 10일

JS

목록 보기
28/40
<!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>
    <input type="text" id="inputTag">
    <button onclick="getInput()">클릭</button>
    <input type="text" id="inputTag2">
    <button onclick="getInput2()">h1태그 출력</button>

    <script>
        // 1. getInput 함수 만들기
        // 2. 첫번째 input 요소 가져오기 -> id값을 통해서 -> 변수에 담아주기
        // 3. alert로 입력한 요소를 출력 -> 입력요소명.value

        const getInput = () => {
            let inputval = document.getElementById('inputTag');
            alert(inputval.value);
        }

        // 1. getInput2 함수만들기
        // 2. 두번째 input 요소 가져오기 -> id값을 통해서 -> 변수에 담아주기
        // 3. document.write로 입력한 요소를 출력 -> 입력요소명.value -> (h1태그로 출력)

        const getInput2 = () => {
            let inputval2 = document.getElementById('inputTag2');
            document.write(`<h1>${inputval2.value}</h1>`);
        }

    </script>
</body>
</html>
profile
개발자

0개의 댓글