JavaScript 系列一:第2課

── 基本的變數操作、從 html 取得內容

by applelily

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>線上下單</title>
    <link rel="stylesheet" href="./js_onclick.css">
</head>
<body>
    <div class="bk_img_container">
        <div class="bk_img">
            <img src="https://imgur.com/Y4gjfmp.jpg">
        </div>

    </div>
    <div class="orderPage">
        您好,尊姓大名?
        <input class="input_cust" id="customer_name" type="text"  autofocus /> 
        <button class="btn btn_1" onclick="goOrder()">我要訂購</button>
        <button class="btn btn_2" onclick="aboutMe()">認識工廠</button>
    </div>
    <script src="./js_onclick.js"></script>
</body>
</html>

CSS

body{
    color: #333;
    background-color: #eedada;
    font-family: OpenSansRegular, "微軟正黑體修正", "微軟正黑體", "Microsoft JhengHei", MHei, STHeitiTC-Light, sans-serif, Arial, Helvetica, "Helvetica Neue", Tahoma, Verdana;

}



.bk_img_container {
    position: relative;
    overflow:scroll;
    width: 100%;
    height: 85vh; /* 占满整个视口高度 */
}

.bk_img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* 铺满且不变形 */
    z-index: -1;
}

.orderPage{
    position: absolute;
    top: 20px;
    left:20px; 
    width: 300x;
    height: 100px;
    background-color:  rgba(238, 218, 218 , 50%) ;
    padding-left: 20px; 
    font-size:  1.2rem;
    color:  #653705;
}
.input_cust{
    margin-right: 20px;
    width: 150px;
    height: 30px;
    border: 1px solid #653705 ;
    background-color: white;
   
}
.input_cust:focus { 
    outline: none !important;
    border-color: #653705;
    box-shadow: 0 0 10px #653705;
 }

.btn {
    margin-top: 30px;
    margin-right: 20px;
    font-size: 1.2rem;
    width: 150px;
    height: 50px;
    background-color: #ffeae4;
    color: #653705;
    border:0px;
    cursor: pointer;
}


.btn_2{
    color: white;
    background-color: #653705;
}

.btn:hover{
    transform: scale(1.1);
}

JavaScript

function goOrder(){
    const custName= document.getElementById('customer_name').value;
    const myMsg = '謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!';
    const msg = custName + ', '+ myMsg;
    alert(msg);
};
function aboutMe(){
    alert('我們工廠位於新北市,通過國際 ISO9001 認證,品質讓您放心!');
}