왕초보 시작반 2주차 숙제

Talysa Lee·2021년 8월 9일
0

스파르타코딩클럽

목록 보기
2/12

jQuery를 굉장히 오랜만에 써봤는데,
특정 element에서 가져온 값을 문자열에 넣는 게 잘 안 됐다.
$가 jQuery를 사용한다는 의미의 확장자라는 것까지는 이해했는데
아래와 같이 동작해서 어리둥절하여 질문을 해 두었다.
다음 주 수업 전에는 답변 주시려나...?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>질문을 위한 페이지</title>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <script>
        //"test"라는 값 입력하여 결과 확인
        function q3() {
            let q3_value = $('#input-q3').val();
            console.log(q3_value);
            // test

            let temp_html_01 = '<li>${q3_value}</li>';
            console.log(temp_html_01);
            // <li>${q3_value}</li>

            let temp_html_02 = '<li>' + q3_value + '</li>';
            console.log(temp_html_02);
            // <li>test</li>

            let temp_html_03 = '<li>' + $('#input-q3').val() + '</li>';
            console.log(temp_html_03);
            // <li>test</li>
        }
    </script>
</head>
<body>
    <input id="input-q3" type="text" placeholder="여기에 이름을 입력" />
    <button onclick="q3()">이름 붙이기</button>
</body>
</html>

0개의 댓글