-
글쓴이글
-
2022년 5월 23일 13:34 #34679
Heok Joon참가자var information0 = $(this).siblings('h5').html();
var information1 = $(this).siblings("p").html();var information0 = $(".buy").eq(3).siblings("h5").html();
var information1 = $(".buy").eq(3).siblings("p").html();
var inform0 = JSON.stringify(information0);
var inform1 = JSON.stringify(information1);this 도 작동이 안되고 . eq()도 작동이 되지 않습니다 어떻게 해야할까요 ?
해당 선택의 형제요소의 값을 어떻게 끌어와야 할지 모르겠네요
2022년 5월 23일 16:08 #34692
Heok Joon참가자상황은 대충 이러한데요
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /><!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script><title>Hello, world!</title>
</head>
<body>
<div class="container">
<div class="row"></div>
</div><script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"
></script><script>
var products = [
{ id: 0, price: 70000, title: "Blossom Dress" },
{ id: 1, price: 50000, title: "Springfield Shirt" },
{ id: 2, price: 60000, title: "Black Monastery" },
];for (a = 0; a++; a < 3) {
if (a < 3) {
console.log(products[a].title.value);
}
}function 내용(받아옴) {
받아옴.forEach((a, i) => {
var 카드 = `<div class="col-sm-4">
<img src="https://via.placeholder.com/600" class="w-100" />
<h5 id="title">${a.title}</h5>
<p id = "price">${a.price}</p>
<button class ="buy">구매</button>
</div>`;
$(".row").append(카드);
});
}var arr = [1, 2, 3];
var newArr = JSON.stringify(arr);localStorage.setItem("num", newArr);
var 꺼낸거 = localStorage.getItem("num");
console.log(JSON.parse(꺼낸거));내용(products);
var information0 = $(".buy").eq(3).siblings("h5").html();
var information1 = $(".buy").eq(3).siblings("p").html();
var inform0 = JSON.stringify(information0);
var inform1 = JSON.stringify(information1);$(".buy")
.eq(1)
.on("click", function () {
localStorage.setItem("key11", inform0 + inform1);
});</script>
</body>
</html>그냥 여러개 html 만들어져 있는것에 몇번째 html 에 h5 이런건 구할수 있을것 같은데
이렇게 JS에서 집어 넣어진 HTML 값은 도출해내려고 해도 잘 안되네요
-
글쓴이글
- 답변은 로그인 후 가능합니다.