let a = 123123;
a = "";
console.log(a); // "" 빈 값이 뜬다.
let a;
console.log(a) //undefined가 뜬다.
let a = 0;
a = a + 2;
a = a + 4;
//a는 6이다.
<h1>abcde</h1>
<button>버튼</button>
let text = $("h1").text();
//h1 tag의 content를 변수에 저장한다.
$("button").on("click", function () {
$("h1").text("");
//h1 tag의 content를 없앤다.
typetext = "";
//빈 변수를 만든다.
setTimeout(() => {
typetext = typetext + text[0];
//문자열의 맨 처음 알파벳을 빈 변수에 저장시킨다.
$("h1").text(typetext);
//h1 tag에 content에 "a"를 넣는다.
}, 500);
//0.5초 실행시킨다.
setTimeout(() => {
typetext = typetext + text[1];
//"a"가 담긴 변수에 "b"를 추가한다. -> "ab"
$("h1").text(typetext);
//h1 tag에 content에 "ab"를 넣는다.
}, 1000);
//1초후에 실행시킨다.
setTimeout(() => {
typetext = typetext + text[2];
$("h1").text(typetext);
}, 1500);
setTimeout(() => {
typetext = typetext + text[3];
$("h1").text(typetext);
}, 2000);
setTimeout(() => {
typetext = typetext + text[4];
$("h1").text(typetext);
}, 2500);
});
문자열의 길이
로 조정$("button").on("click", function () {
$("h1").text("");
//h1 tag의 content를 없앤다.
typetext = "";
//빈 변수를 만든다.
for (let i = 0; i < text.length; i++) {
setTimeout(() => {
typetext = typetext + text[i];
$("h1").text(typetext);
}, 500 * i);
}
});
기
를 검색하면, 식기세척기의 상품카드가 떠야한다.레
를 검색하면, 원목침대프레
임과 시원한 서큘레
이터 2가지 상품 카드가 떠야한다.MakeProductCard(2)
를 통해서 2가지 상품카드 html을 만듬inputProductData(1)
을 통해서 상품카드에 데이터를 넣으려고 했음//상품 카드 만드는 함수
function MakeProductCard(NumberOfCard) {
let productCard = "";
let productPrice = "";
for (let i = 0; i < NumberOfCard; i++) {
productCard += `<div class="product-card">
<div class="img-box">
<img src="pr1.JPG" class="img"/>
</div>
<div class="product-text">
<p class="product-name product-name"></p>
<p class="product-seller product-seller"></p>
</div>
</div>`;
productPrice += `<div class="product-price">
<span class="product-price__number product-price__number"></span>
</div>`;
}
$(".product-card__container").append(productCard);
$(".product-price__container").append(productPrice);
}
//상품데이터
```json
{
"products": [
{
"id": 0,
"product_name": "식기세척기",
"brand_name": "세척나라",
"photo": "pr1.jpg",
"price": 100000
},
{
"id": 1,
"product_name": "원목 침대 프레임",
"brand_name": "침대나라",
"photo": "pr2.jpg",
"price": 200000
},
{
"id": 2,
"product_name": "천연 디퓨저 세트",
"brand_name": "향기나라",
"photo": "pr3.jpg",
"price": 300000
},
{
"id": 3,
"product_name": "시원한 서큘레이터",
"brand_name": "바람나라",
"photo": "pr4.jpg",
"price": 400000
},
{
"id": 4,
"product_name": "맥북",
"brand_name": "애플나라",
"photo": "pr4.jpg",
"price": 1500000
}
]
}
//상품카드에 데이터 넣는 함수
function inputProductData(data) {
$.ajax({
url: "store.json",
type: "GET",
}).done(function (e) {
$(".img").attr("src", e.products[data].photo);
$(".product-name").text(e.products[data].product_name);
$(".product-seller").text(e.products[data].brand_name);
$(".product-price__number").text(e.products[data].price);
});
}
//검색 매커니즘
$(".input").on("input", function () {
$(".product-card__container").html("");
$(".product-price__container").html("");
if ($(".input").val() === "레" || $(".input").val() === "원")
//input창에 `레` 검색하는 것을 인지한다.
$(".product-card__container").html("");
$(".product-price__container").html("");
MakeProductCard(2);
inputProductData(1);
inputProductData(3);
} else if (){}
...
}
MakeProductCard(2);
inputProductData(0);
function MakeProductCard(NumberOfCard) {
let productCard = "";
let productPrice = "";
for (let i = 0; i < NumberOfCard; i++) {
productCard += `<div class="product-card">
<div class="img-box">
<img src="pr1.JPG" class="img${i}"/>
</div>
<div class="product-text">
<p class="product-name product-name${i}"></p>
<p class="product-seller product-seller${i}"></p>
</div>
</div>`;
productPrice += `<div class="product-price">
<span class="product-price__number product-price__number${i}"></span>
</div>`;
}
$(".product-card__container").append(productCard);
$(".product-price__container").append(productPrice);
}
function inputProductData(NumberOfCard, data) {
$.ajax({
url: "store.json",
type: "GET",
}).done(function (e) {
$(".img" + NumberOfCard).attr("src", e.products[data].photo);
$(".product-name" + NumberOfCard).text(e.products[data].product_name);
$(".product-seller" + NumberOfCard).text(e.products[data].brand_name);
$(".product-price__number" + NumberOfCard).text(e.products[data].price);
});
}
//json 데이터 문법
{
"products": [
{
"id": 0,
"product_name": "식기세척기",
"brand_name": "세척나라",
"photo": "pr1.jpg",
"price": 100000
},
{
"id": 1,
"product_name": "원목 침대 프레임",
"brand_name": "침대나라",
"photo": "pr2.jpg",
"price": 200000
},
{
"id": 2,
"product_name": "천연 디퓨저 세트",
"brand_name": "향기나라",
"photo": "pr3.jpg",
"price": 300000
},
{
"id": 3,
"product_name": "시원한 서큘레이터",
"brand_name": "바람나라",
"photo": "pr4.jpg",
"price": 400000
}
]
}
$.ajax({
url: "store.json"
type: "GET"
}).done(function(e){
$(".product-name").html(e.products[0].brand_name);
})