JSFiddle - React, Tailwind, and code Playground
HTML
<div class="container">
<input class="input" type="text" placeholder="請輸入姓名">
<select class="clothes-style">
<option value="" selected disabled>款式</option>
<option value="man">男裝</option>
<option value="woman">女裝</option>
</select>
<select class="clothes-type">
<option value="" selected disabled>類型</option>
<option value="coat">外套</option>
<option value="Jacket">上衣</option>
<option value="Pants">下身</option>
</select>
<div class="btn">
<button class="show" onclick=show()>我要訂購</button>
<button class="about" onclick=about()>認識工廠</button>
</div>
<ul class="lists">
<li class="title">您的訂單</li>
<li>顧客姓名: <span class="custom-name"></span></li>
<li>服裝分類: <span class="clothing-style"></span></li>
<li>服裝類型: <span class="clothing-type"></span></li>
<li>初步估價: <span class="inital-valuation"></span></li>
</ul>
</div>
SCSS
.container {
width: fit-content;
margin: 50px auto;
}
.input, select {
outline: none;
border: none;
font-size: 24px;
background-color: #aaa;
color: #fff;
border-radius: 8px;
padding: 5px;
font-weight: bold;
width: 100%;
}
select {
margin-top: 10px;
}
.input::placeholder {
color: #fff;
}
.show, .about {
padding: 10px;
display: inline-block;
border: 0;
background-color: #fa0;
font-size: 24px;
color: blue;
font-weight: bold;
border-radius: 10px;
box-shadow: 5px 5px 5px #ccc;
cursor: pointer;
}
.btn {
margin-top: 20px;
width: 100%;
padding: 10px;
display: flex;
justify-content: space-between;
}
.show:hover, .about:hover {
transform: scale(1.2);
color: white;
background-color: #aaa;
}
.lists {
background-color: #ccc;
border-radius: 8px;
padding-bottom: 20px;
li + li {
margin-top: 10px;
}
.title {
font-size: 24px;
font-weight: bold;
text-align: center;
border-bottom: 1px solid #000;
padding: 8px 0;
}
li:not(:nth-child(1)) {
font-size: 18px;
font-weight: 400;
display: flex;
justify-content: space-around;
}
}
JavaScript
const input = document.querySelector('.input');
const clothesStyle = document.querySelector('.clothes-style');
const clothesType = document.querySelector('.clothes-type');
function show() {
let sellMessage = '';
let name = input.value;
const message = `${name}您好,謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!`;
let valuation = 0;
let styleIndex = clothesStyle.selectedIndex;
let styleText = clothesStyle.options[styleIndex].text;
let styleValue = clothesStyle.options[styleIndex].value;
let typeIndex = clothesType.selectedIndex;
let typeText = clothesType.options[typeIndex].text;
let typeValue = clothesType.options[typeIndex].value;
if (name.trim() === '') return alert('請輸入姓名');
if (styleValue === '') return alert('請選擇款式');
if (typeValue === '') return alert('請選擇類型');
if (styleValue === 'man') {
sellMessage = '最近剛好是工廠週年慶,只要您今天來電下單,我們將贈送您帥氣領帶!';
valuation = 600;
} else {
sellMessage = '最近剛好是工廠週年慶,只要您今天來電下單,我們將贈送您美麗圍巾!';
valuation = 500;
}
alert(message);
alert(sellMessage);
document.querySelector('.custom-name').textContent = name;
document.querySelector('.clothing-style').textContent = styleText;
document.querySelector('.clothing-type').textContent = typeText;
document.querySelector('.inital-valuation').textContent = valuation;
document.querySelector('.input').value = '';
document.querySelector('.clothes-style').value = '';
document.querySelector('.clothes-type').value = '';
};
function about() {
const message = `我們工廠位於新北市,通過國際 ISO9001 認證,品質讓您放心!`;
alert(message);
};