JSFiddle - React, Tailwind, and code Playground

by ZooeyLai

HTML

<div class="wrap">
        <div class="form">
            <div class="form-group">
                <label for="name" class="form-label">顧客姓名</label>
                <input type="text" id="name" class="form-input" placeholder="請輸入姓名">
            </div>
            <div class="form-group">
                <label for="mySort" class="form-label">服裝分類</label>
                <select name="mySort" id="mySort" class="form-input">
                    <option value="mens">男裝</option>
                    <option value="dress">女裝</option>
                </select>
            </div>  
            <div class="form-group">
                <label for="myType" class="form-label">服裝類型</label>
                <select name="myType" id="myType" class="form-input">
                    <option value="coats">外套</option>
                    <option value="tops">上衣</option>
                    <option value="bottoms">下身</option>
                </select>
            </div>            
        </div>

        <div class="button-group">
            <button class="btn btn-primary" onclick="myOrder()">我要訂購</button>
            <button class="btn btn-outline-primary" onclick="aboutFactory()">認識工廠</button>
        </div>
        <div class="order-info">
            <h3 class="h3">您的訂單</h3>
            <div class="list-group">
                <span>顧客姓名:</span>
                <span id="customer"></span>
            </div>
            <div class="list-group">
                <span>服裝分類:</span>
                <span id="selectClothesSort"></span>
            </div>
            <div class="list-group">
                <span>服裝類型:</span>
                <span id="selectClothesType"></span>
            </div>
        </div>
    </div>

CSS

:root{
    --primary: #4f46e5;
    --gray: #e2e8f0;
    --white: #fff;
}
*{
    box-sizing: border-box;
    font-size: 1rem;
}
.h3{
    margin: 0;
    margin-bottom: 1rem;
    font-size: 1.5rem;
    text-align: center;
}
.wrap{
    width: 80%;
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 0 auto;
    align-items: center;
    flex-flow: column;
}
.button-group{
    display: flex;
    gap: 20px;
}
.btn{
    padding: 0.5rem 1rem;
    border: 2px solid transparent;
    border-radius: 0.25rem;
    background-color: var(--gray);
    color: #475569;
    cursor: pointer;
}
.btn:hover{
  transform: scale(1.1);
  transition: all 0.3s;
}
.btn-primary{
    background-color: var(--primary);
    color: var(--white);
}
.btn-primary:hover{
    background-color: #3730a3;
}

.btn-outline-primary{
    border-color: var(--primary);
    color: var(--primary);
    background-color: var(--white);
}
.btn-outline-primary:hover{
    background-color: var(--primary);
    color: var(--white);
}

.form-group{
    margin-bottom: 1rem;
    display: flex;
    flex-flow: column;
}
.form-label{
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
}
.form-input{
    border: 1px solid #94a3b8;
    padding: 0.5rem 1rem;
    border-radius: 0.25rem;
}
.form-input:focus{
    border-color: var(--primary);
    box-shadow: 0px 0px 0px 3px rgb(79 70 229 / 40%);
    outline: none;
}
.order-info{
    width: 100%;
    background: #e2e8f0;
    padding: 1.25rem;
    border-radius: 0.25rem;
    display: flex;
    flex-flow: column;
}
.list-group{
    margin-bottom: 1rem;
}

JavaScript

function myOrder(){
            // 取得顧客姓名
            let userName = document.getElementById('name').value;

            // 取得分類索引
            let clothes = document.getElementById('mySort');
            let clothesSortIndex = clothes.selectedIndex;

            // 取得分類value
            let sortValue = clothes.options[clothesSortIndex].value;

            // 取得分類文字
            let sortText = clothes.options[clothesSortIndex].text;

            // 取得類型索引
            let clothesType = document.getElementById('myType');
            let clothesTypeIndex = clothesType.selectedIndex;

            // 取得類型value
            let typeValue = clothesType.options[clothesTypeIndex].value;

            // 取得類型文字
            let typeText = clothesType.options[clothesTypeIndex].text;

            // alert(sortText);
            alert(userName + '您好!謝謝您對我們的衣服有興趣!請致電 0987-654-321,會有專人提供您報價!');
            document.getElementById('customer').textContent = userName;
            document.getElementById('selectClothesSort').textContent = sortText;
            document.getElementById('selectClothesType').textContent = typeText;
        }
        
        function aboutFactory(){
            alert('我們工廠位於新北市,通過國際 ISO9001 認證,品質讓您放心!');
        }