Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript로 드롭다운 목록에서 옵션을 제거하는 방법은 무엇입니까?

<시간/>

드롭다운 목록에서 옵션을 제거하려면 JavaScript에서 remove() 메서드를 사용하세요. 드롭다운에서 옵션을 제거하는 방법을 배우기 위해 다음 코드를 실행할 수 있습니다 -

예시

<!DOCTYPE html>
<html>
   <body>
      <form id = "myForm">
         <select id = "selectNow">
            <option>One</option>
            <option>Two</option>
            <option>Three</option>
         </select>
         <input type = "button" onclick = "remove()" value = "Click to Remove">
      </form>
      <p>Select and click the button to remove the selected option.</p>
      
      <script>
         function remove() {
            var x = document.getElementById("selectNow");
            x.remove(x.selectedIndex);
         }
      </script>
      
   </body>
</html>