티스토리 뷰

1. 자바스크립트로 Alert 띄우기

  -함수를 만들어주기

function hey(){
	alert('안녕!');
}

 *script 태그 안에 자바스크립트를 작성한다.

 

 -버튼에 함수를 연결하기 > 버튼을 누르면 함수가 불림. 

 > Mac 버튼을 누르면 함수가 나오도록 할 것이다. 

<a class="nav-link" onclick="hey()" href="#">Mac</a>

 > 1. a(하이퍼링크)를

    2. onclick 이벤트가 발생했을 때

    3. hey() 함수가 호출된다. 

더보기

전체 코드

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>개인작</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Nanum+Gothic+Coding&display=swap');

        body {
            font-family: "Nanum Gothic Coding", monospace;
            font-weight: 400;
            font-style: normal;
        }

        .nav {
            border: 1px solid black;
        }

        .product-image {
            width: 800px;
            height: 400px;
            margin: 50px 100px 0px 100px;
        }

        .main {
            display: flex;
            flex-direction: row;
        }

        .review {
            display: flex;
            flex-direction: column;
            margin-top: 50px;
        }

        .review-main {
            width: 100%;
            height: 100px;
            margin-left: auto;

            margin-bottom: 200px;
            padding-right: 20px;
            text-align: right;
        }


        .review-second {
            margin-bottom: 100px;

        }
    </style>

<script>

function hey(){
	alert('안녕!');
}

    let fruits = ['사과','배','감','귤']
fruits.forEach((a) => {
	console.log(a)
    })
</script>
</head>

<body>
    <div>
        <nav class="nav">
            <a class="nav-link active" aria-current="page" href="#" onclick="hey()">홈</a>
            <a class="nav-link" onclick="hey()" href="#">Mac</a>
            <a class="nav-link" href="#">Ipad</a>
            <a class="nav-link" href="#">Iphone</a>
            <a class="nav-link" href="#">Watch</a>
            <a class="nav-link" href="#">Airpods</a>
            <a class="nav-link disabled" aria-disabled="true">Disabled</a>
        </nav>
    </div>
    <div class="main">
        <div class="product-image">
            <div id="carouselExample" class="carousel slide">
                <div class="carousel-inner">
                    <div class="carousel-item active">
                        <img src="https://images.unsplash.com/photo-1517336714731-489689fd1ca8?q=80&w=2826&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
                            class="d-block w-100" alt="...">
                    </div>
                    <div class="carousel-item">
                        <img src="https://via.placeholder.com/800x400" class="d-block w-100" alt="Placeholder Image">
                    </div>
                    <div class="carousel-item">
                        <img src="https://via.placeholder.com/800x400" class="d-block w-100" alt="Placeholder Image">
                    </div>
                </div>
                <button class="carousel-control-prev" type="button" data-bs-target="#carouselExample"
                    data-bs-slide="prev">
                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                    <span class="visually-hidden">Previous</span>
                </button>
                <button class="carousel-control-next" type="button" data-bs-target="#carouselExample"
                    data-bs-slide="next">
                    <span class="carousel-control-next-icon" aria-hidden="true"></span>
                    <span class="visually-hidden">Next</span>
                </button>
            </div>
        </div>
        <div class="review">
            <div class="review-main">
                <h1>가장 화려한 노트북</h1>
                <h5>맥북에어 m1 가성비 좋아요 짱</h5>
            </div>
            <div class="review-second">
                <div class="form-floating mb-3">
                    <input type="email" class="form-control" id="floatingInputDisabled" placeholder="name@example.com"
                        disabled>
                    <label for="floatingInputDisabled">이메일</label>
                </div>
                <div class="form-floating mb-3">
                    <textarea class="form-control" placeholder="리뷰 제목" id="floatingTextareaDisabled"
                        disabled></textarea>
                    <label for="floatingTextareaDisabled">리뷰 제목</label>
                </div>
                <div class="form-floating mb-3">
                    <textarea class="form-control" placeholder="리뷰 내용" id="floatingTextarea2Disabled"
                        style="height: 100px" disabled></textarea>
                    <label for="floatingTextarea2Disabled">리뷰 내용</label>
                </div>
                <div class="form-floating">
                    <select class="form-select" id="floatingSelectDisabled"
                        aria-label="Floating label disabled select example" disabled>
                        <option selected>별점</option>
                        <option value="1">★</option>
                        <option value="2">★★</option>
                        <option value="3">★★★</option>
                        <option value="4">★★★★</option>
                        <option value="5">★★★★★</option>
                    </select>
                    <label for="floatingSelectDisabled">별점</label>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"></script>
</body>

</html>

-짠! 잘 호출된다. 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함