HTML
<select id="mySelect">
<option optGroup='a'>1</option>
<option optGroup='a'>1</option>
<option optGroup='a'>1</option>
<option optGroup='b'>2</option>
<option optGroup='b'>2</option>
</select>
JQueryfunction SetupOptGroups(select) {
var optGroups=new Array();
var i = 0;
$(select).find("[optGroup]").each(function(index, domEle) {
var optGroup = $(this).attr("optGroup");
if ($.inArray(optGroup, optGroups)==-1) optGroups[i++] = optGroup;
});
for(i=0; i < optGroups.length; i++){
$("option[optGroup='"+optGroups[i]+"']").wrapAll("<optgroup label='"+optGroups[i]+"'>");
}
}
No comments:
Post a Comment