我有這個頁面的 3 個 html 檔案。index.html,正面評價頁面和負面評價頁面。我希望我的 JavaScript 在單擊表情符號反饋然后單擊按鈕后重定向到頁面。根據點擊的表情符號點擊按鈕后,如果選擇的表情符號是中性或不愉快的,并且如果選擇的表情符號滿足重定向到正面評論頁面,它應該重定向到負面評論頁面。我是新手,堅持使用以下代碼。下面的代碼帶我回到正面評價頁面。
const sendButton = document.querySelector("#send");
const panelContainer = document.querySelector(".panel-container");
const ratings = document.querySelectorAll(".rating");
const experience = document.querySelectorAll("small");
sendButton.addEventListener("click", () => {
for (let i = 0; i < experience.length; i ) {
// console.log(experience[i].innerHTML);
if (
experience[i].innerHTML === "Unhappy" ||
experience[i].innerHTML === "Neutral"
) {
window.location = "negative_review.html";
} else {
window.location = "positive_review.html";
}
}
});
This is the index page only.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css"
/>
<link rel="stylesheet" href="style.css" />
<title>Feedback</title>
</head>
<body>
<div id="panel" class="panel-container">
<h2>Welcome Text</h2>
<strong
>How was your experience <br />
with us?
</strong>
<div class="ratings-container">
<div class="rating">
<img
src="https://cdn-icons-png.flaticon.com/128/742/742752.png"
alt=""
/>
<small>Unhappy</small>
</div>
<div class="rating">
<img
src="https://cdn-icons-png.flaticon.com/128/725/725085.png"
alt=""
/>
<small>Neutral</small>
</div>
<div class="rating active">
<img
src="https://cdn-icons-png.flaticon.com/128/166/166549.png"
alt=""
/>
<small>Satisfied</small>
</div>
</div>
<form>
<label for="feedback">Please Tell Us About Your Experience</label>
<textarea name="" id="" maxlength="350" cols="30" rows="10"></textarea>
</form>
<button class="btn" id="send">Send Review</button>
</div>
<script src="script.js"></script>
</body>
</html>
uj5u.com熱心網友回復:
看起來正確的使用體驗是被<div >
sendButton.addEventListener("click", () => {
const experience = document.querySelector(".rating.active small");
if (
experience[i].innerHTML === "Unhappy" ||
experience[i].innerHTML === "Neutral"
) {
window.location = "negative_review.html";
} else {
window.location = "positive_review.html";
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/512300.html
上一篇:如何在document.createElement上創建監聽器?
下一篇:修復傾斜/傾斜的文本Opencv
