실시간 서울 날씨 자동 로딩 함수 & 날씨 API
$(document).ready(function() {
fetch("http://spartacodingclub.shop/sparta_api/weather/seoul").then(res => res.json()).then(data => {
console.log(data)
})
})
✅
- 내 생애 최고의 영화들 제목과 영화 기록하기 버튼 사이에 현재 서울의 날씨 뼈대 추가
- fetch를 사용해 값을 가져오기
- 백틱을 사용해, 뼈대/문자/변수를 모두 섞어서 붙여보기
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<title> 스파르타코딩클럽 | 부트스트랩 연습하기</title>
<style>
* {
font-family: 'Gowun Dodum', sans-serif;
}
.mytitle {
background-color: green;
color: white;
height: 250px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-image: linear-gradient(0deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://img.hani.co.kr/imgdb/resize/2017/1128/00502224_20171128.JPG');
background-position: center;
background-size: cover;
}
.mytitle>button {
width: 250px;
height: 50px;
background-color: transparent;
border: 1px solid white;
color: white;
border-radius: 50px;
margin-top: 20px;
}
.mytitle>button:hover {
border: 2px solid white;
}
.mycomment {
color: gray;
}
.mycards {
width: 1200px;
margin: 20px auto 20px auto;
}
.mypost {
width: 500px;
margin: 20px auto 20px auto;
padding: 20px 20px 20px 20px;
box-shadow: 0px 0px 3px 0px gray;
}
.mybtn {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
margin-top: 20px;
}
.mybtn>button {
margin-right: 10px;
}
</style>
<script>
$(document).ready(function () {
fetch("http://spartacodingclub.shop/sparta_api/weather/seoul").then(res => res.json()).then(data => {
let number = data['temp']
$('#temp').text(number)
})
})
</script>
</head>
<body>
<div class="mytitle">
<h1>내 생애 최고의 영화들</h1>
<div>현재 서울의 날씨 : <span id="temp">20</span>도</div>
<button onclick="hey()">영화 기록하기</button>
</div>
<div class="mypost">
<div class="form-floating mb-3">
<input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
<label for="floatingInput">영화URL</label>
</div>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">별점</label>
<select class="form-select" id="inputGroupSelect01">
<option selected> --- 선택하기 --- </option>
<option value="1">⭐</option>
<option value="2">⭐⭐</option>
<option value="3">⭐⭐⭐</option>
<option value="4">⭐⭐⭐⭐</option>
<option value="5">⭐⭐⭐⭐⭐</option>
</select>
</div>
<div class="form-floating">
<textarea class="form-control" placeholder="Leave a comment here" id="floatingTextarea"></textarea>
<label for="floatingTextarea">코멘트</label>
</div>
<div class="mybtn">
<button type="button" class="btn btn-secondary">기록하기</button>
<button type="button" class="btn btn-outline-secondary">닫기</button>
</div>
</div>
<div class="mycards">
<div class="row row-cols-1 row-cols-md-4 g-4">
<div class="col">
<div class="card h-100">
alt="...">
<div class="card-body">
<h5 class="card-title">영화 제목</h5>
<p class="card-text">영화 설명</p>
<p>⭐⭐⭐⭐⭐</p>
<p class="mycomment">나의 코멘트</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
alt="...">
<div class="card-body">
<h5 class="card-title">영화 제목</h5>
<p class="card-text">영화 설명</p>
<p>⭐⭐⭐⭐⭐</p>
<p class="mycomment">나의 코멘트</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
alt="...">
<div class="card-body">
<h5 class="card-title">영화 제목</h5>
<p class="card-text">영화 설명</p>
<p>⭐⭐⭐⭐⭐</p>
<p class="mycomment">나의 코멘트</p>
</div>
</div>
</div>
<div class="col">
<div class="card h-100">
alt="...">
<div class="card-body">
<h5 class="card-title">영화 제목</h5>
<p class="card-text">영화 설명</p>
<p>⭐⭐⭐⭐⭐</p>
<p class="mycomment">나의 코멘트</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
'Javascript' 카테고리의 다른 글
JS문법 : 변수와 상수 (0) | 2023.07.24 |
---|---|
Javascript의 역사 (1995~) (0) | 2023.07.24 |
fetch 반복문 / 조건문 (0) | 2023.07.13 |
fetch / forEach / $('#id').append(temp_html) (0) | 2023.07.12 |
Fetch / console.log(data) (0) | 2023.07.12 |