Hi,歡迎訪問前端老白
<p><label>請選擇一個選項:</label></p> <p><select></p> <p><option value="option1">選項1</option></p> <p><option value="option2">選項2</option></p> <p><option value="option3">選項3</option></p> <p></select></p>
<p><label>請選擇一個選項:</label></p> <p><select id="mySelect"></p> <p><option value="option1">選項1</option></p> <p><option value="option2">選項2</option></p> <p><option value="option3">選項3</option></p> <p></select></p> <p><script></p> <p>let select = document.getElementById('mySelect');</p> <p></script></p>
<p><button onclick="addOption()">添加新選項</button></p> <p><script></p> <p>let select = document.getElementById('mySelect');</p> <p>function addOption() {</p> <p>let option = document.createElement('option');</p> <p>option.value = 'option4';</p> <p>option.innerHTML = '選項4';</p> <p>select.add(option, 3);</p> <p>}</p> <p></script></p>
<p><button onclick="removeOption()">刪除選項2</button></p> <p><script></p> <p>let select = document.getElementById('mySelect');</p> <p>function removeOption() {</p> <p>select.remove(1);</p> <p>}</p> <p></script></p>
<p><label for="mySelect">當前選擇:</label></p> <p><span id="currentOption"></span></p> <p><script></p> <p>let select = document.getElementById('mySelect');</p> <p>let currentOption = document.getElementById('currentOption');</p> <p>select.addEventListener('change', function() {</p> <p>currentOption.innerHTML = select.value;</p> <p>});</p> <p></script></p>
老白網(wǎng)絡 (http://www.lofty888.cn/) 前端 后端 zblog主題.網(wǎng)站地圖xml