我有一个名为 tmp 的数组
var tmp = ["05", "13", "27"];
如果选项值等于 tmp 中的值,我想将该选项添加到特定的 optgroup,否则将其添加到另一个 optgroup。我不断地将所有内容添加到 optgroup #2,但值为“27”的选项除外。我做错了什么?
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 在圣地亚哥