このコードを使用して、ドロップダウン リスト コントロールの項目をグループ化します。
var item;
var GroupsGRP = jQuery('<optgroup/>', {
label: 'Groups'
}).appendTo(selectControl);
var EmployeesGRP = jQuery('<optgroup/>', {
label: 'Employees'
}).appendTo(selectControl);
jQuery('option', selectControl).each(function (i) {
item = jQuery(this);
if (item.attr("class") == 'Employees') {
item.appendTo(EmployeesGRP);
}
else {
item.appendTo(GroupsGRP);
}
});
そして、これの出力は次のとおりです。
Employees
Employee number one
Employee number two
Groups
Group number one
Group number two
質問:
項目がない場合、グループ ヘッダーを削除するにはどうすればよいですか?