注: 1、optgroup开始结束标签间不能有空格,否则optgroup.hasChildNodes() 始终为true. 2、增加了排序功能,先optgroup中options按value排序,然后按照otpgroup标签排序. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>select-optgroup</title> <head> <mce:script type="text/javascript"><!-- function CreateOptgroup(obj,obj1,value,text){ var addoption = document.createElement("option"); addoption.value = value; addoption.appendChild(document.createTextNode(text)); var addoptgroup = document.createElement("optgroup"); var optgroup=obj.options[obj.selectedIndex].parentNode; if(optgroup.label) { addoptgroup.label = optgroup.label; if(obj1.length==0) { addoptgroup.appendChild(addoption); obj1.appendChild(addoptgroup); } var i; var optgroup1; for(i=0