tmp という配列があります
var tmp = ["05", "13", "27"];
オプション値が tmp 内の値と等しい場合は、そのオプションを特定の optgroup に追加し、そうでない場合は他の optgroup に追加します。値が「27」のオプションを除いて、すべてを optgroup #2 に追加し続けています。私は間違って何をしていますか?
var groups = $("optgroup");
$("option").each(function() {
var value = $(this).val();
for (var x = 0; x < tmp.length; x++) {
var isMatch = (tmp[x] === value);
if (isMatch) {
$(this).appendTo($(groups[0]));
} else if (value.length > 0) {
$(this).appendTo($(groups[1]));
}
}
});
これを修正するための指針をありがとう。
~ck in サンディエゴ