JSFiddle - React, Tailwind, and code Playground
HTML
<label class="input-text">Name: <input class="input" type="text" placeholder="請輸入姓名"></label>
<div class="btn">
<button class="show" onclick=show()>我要訂購</button>
<button class="about" onclick=about()>認識工廠</button>
</div>
<ul class="lists">
<li class="title">您的訂單</li>
<li class="name">顧客姓名: <span class="custom-name"></span></li>
</ul>
SCSS
* {
list-style: none;
padding: 0;
}
.input-text {
margin-bottom: 10px;
font-size: 24px;
}
.input {
outline: none;
border: none;
font-size: 24px;
background-color: #aaa;
color: #fff;
border-radius: 8px;
padding: 5px;
font-weight: bold;
}
.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;
}
button + button {
margin-left: 10px;
}
.show:hover, .about:hover {
transform: scale(1.2);
color: white;
background-color: #aaa;
}
.lists {
background-color: #ccc;
width: 300px;
height: 300px;
li + li {
margin-top: 10px;
}
.title {
font-size: 24px;
font-weight: bold;
text-align: center;
border-bottom: 1px solid #000;
padding: 8px 0;
}
.name {
font-size: 18px;
font-weight: 400;
display: flex;
justify-content: space-evenly;
.custom-name {
font-size: 18px;
}
}
}
JavaScript
function show() {
let name = document.querySelector('.input').value;
if(name.trim() === '') return alert('請輸入姓名');
const message = `${name}您好,謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!`;
alert(message);
document.querySelector('.custom-name').textContent = name
document.querySelector('.input').value = '';
};
function about() {
const message = `我們工廠位於新北市,通過國際 ISO9001 認證,品質讓您放心!`;
alert(message);
};