HTML:关于Select中的OPTGROUP使用
2008-01-02 10:07 imddb 阅读(1032) 评论(0) 编辑 收藏 举报
下面这段代码的精髓在于“Clean Select”也就是每次动态构建Select前先要清空用OPTGROUP分组的Select。
var dropReport = $("dropReport");
// Clean Select
var blank = document.createTextNode('');
while (dropReport.childNodes.length > 0) {
dropReport.replaceChild(blank, dropReport.childNodes[0]);
dropReport.removeChild(blank);
}
var opt = new Option("--------请选择报表--------","");
dropReport.options.add(opt);
var systemGroup = document.createElement("OPTGROUP");
systemGroup.label = 'System';
dropReport.appendChild(systemGroup);
for (var item = items.nextNode();item;item = items.nextNode())
{
var REPORT_TYPE = item.selectSingleNode("REPORT_TYPE").nodeTypedValue;
if (REPORT_TYPE == 'system')
{
var REPORT_ID= item.selectSingleNode("REPORT_ID").nodeTypedValue;
//alert(REPORT_ID);
var REPORT_NAME= item.selectSingleNode("REPORT_NAME").nodeTypedValue;
//alert(REPORT_NAME);
var newOption = document.createElement("OPTION");
newOption.text=REPORT_NAME;
newOption.value=REPORT_ID;
dropReport.options.add(newOption);
}
}
// Clean Select
var blank = document.createTextNode('');
while (dropReport.childNodes.length > 0) {
dropReport.replaceChild(blank, dropReport.childNodes[0]);
dropReport.removeChild(blank);
}
var opt = new Option("--------请选择报表--------","");
dropReport.options.add(opt);
var systemGroup = document.createElement("OPTGROUP");
systemGroup.label = 'System';
dropReport.appendChild(systemGroup);
for (var item = items.nextNode();item;item = items.nextNode())
{
var REPORT_TYPE = item.selectSingleNode("REPORT_TYPE").nodeTypedValue;
if (REPORT_TYPE == 'system')
{
var REPORT_ID= item.selectSingleNode("REPORT_ID").nodeTypedValue;
//alert(REPORT_ID);
var REPORT_NAME= item.selectSingleNode("REPORT_NAME").nodeTypedValue;
//alert(REPORT_NAME);
var newOption = document.createElement("OPTION");
newOption.text=REPORT_NAME;
newOption.value=REPORT_ID;
dropReport.options.add(newOption);
}
}