Display buttons with custom styles and functionality
by rayray0093
HTML
<h1>線上下單</h1>
<fieldset>
<label for="name">姓名:</label><input id="name" type="text">
<button class="button" onclick="orderFunction()">我要訂購</button>
<button class="button" onclick="aboutFunction()">關於我們</button>
<div>
<h4>你的訂單</h4>
<p>顧客姓名:<span class="customName"></span></p>
</div>
</fieldset>
CSS
body {
background-color: gold;
}
h1 {
text-align: center;
margin-top: 45px;
}
.name {
padding: 5px;
border: 2px solid black;
}
fieldset {
background-color: white;
padding: 20px;
width: 200px;
height: auto;
border-radius: 5px;
border: 2px black solid;
/* background-color: black; */
text-align: center;
margin: 0 auto;
margin-top: 10px;
}
.button {
border: 2px solid black;
border-radius: 5px;
color: black;
background-color: white;
margin: 5px;
padding: 5px;
font-family: Arial, Helvetica, sans-serif;
}
.button:hover {
background-color: lightblue;
color: black;
border-color: white;
}
div {
border: 1px black solid;
border-radius: 5px;
margin-top: 10px;
text-align: left;
padding: 5px;
height: 75px;
line-height: 5px;
}
JavaScript
function orderFunction () {
let name = document.getElementById("name").value;
let customName = document.querySelector('.customName');
alert (name+';'+'謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!');
customName.textContent = name;
}
function aboutFunction () {
alert ('我們工廠位於新北市,通過國際 ISO9001 認證,品質讓您放心!');
}