我希望能夠遍歷並記錄下選擇下拉框中可用的每個選項。我不確定在使用$(this)
時如何執行此操作。
這就是我所擁有的。
$('select').each(function(){
$(this).find('options').each(function(){
var boxOpt = $(this).text();
console.log(boxOpt);
});
});
它當前不輸出任何內容。我希望能夠做到這樣的事情: $(this + ' options').each(function(){...});
但這是行不通的。
我試過 $(this).find()
,$(this).children()
和其他一些變化,但我不知道現在該做什麼。
有什麼建議嗎? 謝謝
用於在HTML中選擇有效的兒童是「選項」,而不是「選項」 –
謝謝。這解決了它 – ntgCleaner