tôi muốn lặp qua tất cả thả xuống chọn với một tên lớp nhất định và thêm một mục vào nó và tôi đang chỉ phải vật lộn với bộ chọn đúngBộ chọn jquery chính xác để có được tất cả các trình đơn thả xuống được chọn với một tên lớp nhất định là gì?
EDIT: Tôi phải làm gì đó sai như hầu hết các câu trả lời chấp nhận upvoted dường như không làm việc vì vậy tôi nghĩ rằng phải có một số quirk trong mã của tôi. Tôi đã dán cả HTML và mã jquery bên dưới. cho tôi biết nếu điều này có ý nghĩa.
HTML:
<select onfocus="this.enteredText='';" onkeydown="return handleKey();" onkeyup="event.cancelbubble=true;return false;" onkeypress = "return selectItem();" class="componentSelect" id="components0" name="applicationUpdater.dependencies[0].componentName" >
<option value= 5 >Client</option>
<option value= 79 >Server</option>
</select>
<select onfocus="this.enteredText='';" onkeydown="return handleKey();" onkeyup="event.cancelbubble=true;return false;" onkeypress = "return selectItem();" class="componentSelect" id="components1" name="applicationUpdater.dependencies[0].componentName" >
<option value= 5 >Client</option>
<option value= 79 >Server</option>
</select>
vv. . .
mã jquery:
$('select.componentSelect').each(function() {
var select = $(this);
$(select).children('option').each(function() {
if ($(this).text() == currentComponentName) {
$(this).remove();
}
});
});
Tại sao điều này lại bị bỏ phiếu? – SLaks