Hi all Tôi có một thả xuống như bên dưới:Làm thế nào để Hủy bỏ tất cả các tùy chọn từ một danh sách lí sử dụng Jquery/JS
<select id="models" onchange="removeElements()">
<option id = "remove" value="0">R8</option>
<option id = "remove" value="1">Quattro</option>
<option id = "remove" value="2">A6 hatchback</option>
</select>
thế nào tôi sẽ tạo ra removeElements kịch bản() sẽ loại bỏ tất cả các tùy chọn bên trong lựa chọn?
Bạn hiểu rằng phần id có nghĩa là có một tên duy nhất, không phải là thẻ tùy chọn của bạn. – gsamaras
Lặp lại - http://stackoverflow.com/questions/3364493/how-do-i-clear-all-options-in-a-dropdown-box – Christian
JS đơn giản: 'document.getElementById ('models'). Length = 0' làm điều đó cho tôi. Nếu bạn đã có một tham chiếu đến lựa chọn, thì 'select.length = 0' (xem [HTML5 section 4.10.7] (http://www.w3.org/html/wg/drafts/html/master/forms. html # dom-select-length)). – RobG