JS_lesson2
https://codelove.tw/@howtomakeaturn/post/X3KPBa
by j437437
HTML
<head>
<link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css' rel='stylesheet' />
</head>
<body>
<div class="wrap">
<form>
<input type="text" id="username" required />
<label for="username">請輸入您的大名</label>
<span></span>
</form>
<button onclick="inquiryFunction()" class="btn" type="button">
<i class="fa-solid fa-cart-shopping"></i>
我要訂購
</button>
<button onclick="introFunction()" class="btn" type="button">
<i class="fa-regular fa-building"></i>
認識工廠
</button>
</div>
</body>
CSS
* {
margin: 0;
padding: 0;
color: #fff;
}
body {
background-image: url("https://images.unsplash.com/photo-1523381294911-8d3cead13475?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8NzR8fGZhc2hpb258ZW58MHwwfDB8fA%3D%3D&auto=format&fit=crop&w=500&q=60");
background-repeat: no-repeat;
background-size: cover;
}
.wrap{
margin: 100px 0px;
padding: 50px 0px 50px 80px;
width: 400px;
background-color: rgba(0, 0, 0, 0.2);
}
form {
position: relative;
width: 300px;
font-size: 16px;
font-weight: bold;
margin-bottom: 30px;
}
input {
width: 100%;
padding: 12px 0;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background-color: transparent;
transition: all 0.5s;
}
#username:focus {
border-bottom: 1px solid #fff;
cursor: text;
}
#username ~ label {
color: #fff;
padding: 10px 0;
position: absolute;
top: 0;
left: 0;
transition: all 0.5s;
}
#username:focus ~ label, #username:valid ~ label {
color: #fff;
font-size: 12px;
top: -25px;
left: 0;
}
.btn {
font-size: 16px;
border-radius: 3px;
margin-right: 15px;;
width: 120px;
height: 40px;
border: white;
background-color: #fff;
color: black;
font-weight: bold;
box-shadow: 10px 5px 5px rgba(1, 0, 0, 0.2);
}
.btn i{
display: none;
}
.btn:hover {
cursor: pointer;
background-color: #007979;
color: #fff;
}
.btn:hover i {
cursor: pointer;
background-color: #007979;
color: #fff;
display: inline;
margin-right: 8px;
}
JavaScript
function inquiryFunction() {
const username = document.getElementById('username').value;
alert(`${username} 您好!謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!`)
}
function introFunction() {
const username = document.getElementById('username').value;
alert( username + ' 您好!我們工廠位於新北市,通過國際 ISO9001 認證,品質讓您放心!')
}