jQuery를 사용하면 간단하게 html 끌어올 수 있음.
let result = <li>${구}: ${도}</li>
;
$(ul).append(result);
$(ul).empty()
forEach(()=>{}) // forEach 반복 콜백
element.remove()
요소 지우기
document.getElementById("ul");
HTML에서 ul을 선택하고 그 자식들로 li를 심어줌
ul.append(li)
글자 위치 바꾸는 방법
function solution(my_string, num1, num2) {
var answer = "";
answer = my_string.split(""); //새로운 "" 기준으로 배열로 반환
let str1 = answer[num1];
let str2 = answer[num2];
answer.splice(num1, 1, str2); num1과 하나를 str2와 바꿈
answer.splice(num2, 1, str1); num2과 하나를 str1과 바꿈
return answer;
}
openApi 쉽게 보는 방법(크롬 확장프로그램)
https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc?hl=ko
append 에러 생기면
body 밑에다 script 추가
get방식
사이트이름(www.naver.com)
창구이름(/main/) -req.params로 요청함
주민등록번호(?{key:value}) - res.query로 요청함
서버에서 클라이언트로 전달할 때는
JSON방식으로 {key:value}
fetch 기본골격
fetch("여기에 URL을 입력").then(res => res.json()).then(data => {
console.log(data)
})
Uncaught SyntaxError: Cannot use import statement outside a module
js 백엔드 작업할 때 type="module" 설정해야됨
function q1() {
let url = "http://spartacodingclub.shop/sparta_api/seoulair"; // url을 먼저 변수에 지정해주고
fetch(url) << url을 받음
.then((res) => res.json())
url data>> .then((data) => {
for (let i = 0; i < data.RealtimeCityAir.row.length; i++) {
let 구 = data.RealtimeCityAir.row[i].MSRSTE_NM;
let 도 = data.RealtimeCityAir.row[i].IDEX_MVL;
let result = ${구}: ${도}
;
ul.append(result);
}
});
}
for (let i = 0; i < data.RealtimeCityAir.row.length; i++) {
let 구 = data.RealtimeCityAir.row[i].MSRSTE_NM;
let 도 = data.RealtimeCityAir.row[i].IDEX_MVL;
let result = `; if (도 > 40) { result =