1
爲什麼select
中有optgroups時不工作?選項:第一個孩子在所有情況下都沒有選擇相同
不起作用
$("option:first-child").attr("selected", "selected");
工作
$("select>option:first-child").attr("selected", "selected");
當我做$("select:eq(1) option:first-child").val()
這似乎是獲得正確的option
,但是當我打電話attr()
它沒有選擇正確的一個。
精氨酸!我知道'val()'返回第一個值。大腦放屁告訴我,.attr(「選定」)也是設置第一個的值。愚蠢的屁。謝謝! – Homer