๐ŸŽ›๏ธ<select>

HTML โŸฉ element โŸฉ <select>

The <select> HTML element represents a control that provides a menu of options.

๐Ÿ“ html

<!-- ็”จ <label> ๅŒ…่ฃ <select> ็š„ๆจ™็ฑคๆ–‡ๅญ—่ˆ‡ๆ•ดๅ€‹ไธ‹ๆ‹‰ๅผ้ธๅ–ฎ -->
<label>
    <!-- <select> ๆจ™็ฑคๆ–‡ๅญ— -->
    flex-direction:
    <!-- <select> ไธ‹ๆ‹‰ๅผ้ธๅ–ฎ -->
    <select id="flexDirection">
        <option value="row">row</option>
        <option value="row-reverse">row-reverse</option>
        <option value="column">column</option>
        <option value="column-reverse">column-reverse</option>
    </select>
</label>

๐Ÿ“ js

// 1. ๅ…ˆๆ‰พๅ‡บ id="flex-direction" ็š„ <select> ๅ…ƒ็ด 
const flexDirectionSelect = document.getElementById('flexDirection');

// 2. ็›ฃ่ฝไธ‹ๆ‹‰ๅผ้ธๅ–ฎ็š„่ฎŠๆ›ด
flexDirectionSelect.addEventListener('change', updateFlexbox);

// 3. ๆ นๆ“šไธ‹ๆ‹‰ๅผ้ธๅ–ฎ็š„่ฎŠๆ›ด๏ผŒๅš็›ธๅฐๆ‡‰็š„ๅๆ‡‰(ๆ›ดๆ–ฐ flexbox style ๅฑฌๆ€ง)
function updateFlexbox() {
    flexContainer.style.flexDirection = flexDirectionSelect.value;
}

Last updated