js1-7
by wang_siang
HTML
<main>
<section class="block">
<div>
<label for="name">客戶姓名:</label>
<input type="text" id="name" placeholder="請輸入名字">
</div>
<div>
<label for="gender">服裝分類:</label>
<select id="gender">
<option value="" selected hidden disabled>服裝分類</option>
<option value="male">男裝</option>
<option value="female">女裝</option>
</select>
</div>
<div>
<label for="type">服裝類型:</label>
<select id="type">
<option value="" selected hidden disabled>服裝類型</option>
<option value="jacket">外套</option>
<option value="top">上衣</option>
<option value="bottom">下身</option>
</select>
</div>
<div>
<label for="amount">訂購數量:</label>
<input type="number" id="amount" placeholder="請輸入數量" min="100">
</div>
</section>
<section class="btnblock">
<button type="button" onclick="clickBtn1()">我要訂購</button>
<button type="button" onclick="clickBtn2()">認識工廠</button>
</section>
<section class="orderlist">
<h2 class="title">您的訂單</h2>
<div>顧客姓名:<span id="listName"></span></div>
<div>服裝分類:<span id="listGender"></span></div>
<div>服裝類型:<span id="listType"></span></div>
<div>訂購數量:<span id="listAmount"></span></div>
<div>初步估價:<span id="listPrice"></span></div>
</section>
</main>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
width: 100%;
display: flex;
justify-content: center;
}
main {
font-size: 18px;
font-weight: 600;
padding: 50px;
display: flex;
flex-direction: column;
gap: 40px;
border-radius: 8px;
color: black;
}
.btnblock {
display: flex;
justify-content: space-between;
gap: 10px;
}
button {
padding: 10px 20px;
font-size: 18px;
font-weight: 600;
background-color: #5280ff;
color: white;
box-shadow: 5px 5px 0px black;
border: 3px solid black;
transition: all 0.3s ease;
cursor: pointer;
}
button:hover {
background-color: #fff;
color: #5280ff;
border: 3px solid #5280ff;
box-shadow: 5px 5px 0px #5280ff;
}
button:active {
transform: translateY(4px);
box-shadow: 0px 0px 0px #5280ff;
}
.block {
display: flex;
flex-direction: column;
gap: 30px;
}
.block div {
display: flex;
align-items: center;
gap: 10px;
}
input,
select {
padding: 8px;
font-size: 18px;
border: 3px solid black;
box-shadow: 5px 5px 0px black;
outline: none;
font-weight: 600;
}
input:focus,
select:focus {
border: 3px solid #5280ff;
box-shadow: 5px 5px 0px #5280ff;
transition: all 0.6s ease;
color: #5280ff;
}
option {
font-weight: 600;
}
.orderlist {
padding: 20px;
...
JavaScript
function clickBtn1() {
const name = document.getElementById('name').value;
const amount = parseInt(document.getElementById('amount').value);
const gender = document.getElementById('gender');
const genderIndex = gender.selectedIndex;
const genderText = gender.options[genderIndex].text;
const genderValue = gender.options[genderIndex].value;
const type = document.getElementById('type');
const typeIndex = type.selectedIndex;
const typeText = type.options[typeIndex].text;
const typeValue = type.options[typeIndex].value;
console.log(amount);
if (name == '') {
alert('煩請填寫您的大名。')
return;
}
if (genderValue == '' || typeValue == '') {
alert('煩請選擇服裝分類以及服裝類型。')
return;
};
if (!amount) {
alert('煩請輸入訂購數量')
return;
} else if (amount > 5000) {
alert('抱歉,我們工廠的最高出貨量是 5,000 件。')
return;
} else if (amount < 100) {
alert('抱歉,我們工廠的最低出貨量是 100 件。')
return;
}
alert(name + '您好!謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!');
let price = 0;
if (genderValue == 'male') {
alert('最近剛好是工廠週年慶,只要您今天來電下單,我們將贈送您帥氣領帶!');
price = amount * 600;
} else if (genderValue == 'female') {
alert('最近剛好是工廠週年慶,只要您今天來電下單,我們將贈送您美麗圍巾!');
price = amount * 500;
};
document.getElementById('listName').textContent = name;
document.getElementById('listGender').textContent = genderText;
document.getElementById('listType').textContent = typeText;
document.getElementById('listAmount').textContent = `${amount}個`;
...