// 给下拉框增加项 function insertOption(obj, _text, _value, _selected) { // 如果存在此VALUE,则编辑 for (var i=0; i< obj.length; i++){ if (obj[i].value == _value){ obj[i].text = _text; return; } } // 若不存在此VALUE,新建 var _option = document.createElement("OPTION"); _option.text = _text; _option.value = _value; obj.add(_option); if (_selected) {obj.selectedIndex = obj.length-1;}} // 给下拉框去除某项 function delOption(obj,_value) { for (var i=0; i< obj.length; i++){ if (obj[i].value == _value){ obj.remove(i); return; } }} // 给多行下拉框去除某几项(多项) function delMultiOption(obj,_indexArray) { var offset = 0; for (var i=0; i< _indexArray.length; i++){ obj.options.remove(_indexArray[i]+offset); offset--; }} // 清除选项 function clearOptions(obj) { obj.options.length=0; } function getSelectedOption(obj) { var ret = new Array(); ret[0] = obj.value; ret[1] = obj.options[obj.selectedIndex].text; return ret; } // 多项下拉框的选择项的值 function getMultiSelectedValue(ob,excludeFirst) { var arSelected = new Array(); while (ob.selectedIndex != -1) { if (!(excludeFirst && ob.selectedIndex == 0)){arSelected.push(ob.value);} ob.options[ob.selectedIndex].selected = false; } return arSelected;} // 多项下拉框的选择项的INDEX // ob: 控件 // excludeFirst: 是否排除第一项(第一项有时为说明项) function getMultiSelectedIndex(ob,excludeFirst) { var arSelected = new Array(); while (ob.selectedIndex != -1) { if (!(excludeFirst && ob.selectedIndex == 0)){arSelected.push(ob.selectedIndex);} ob.options[ob.selectedIndex].selected = false; } return arSelected;}
本系统,待补充及完善,长期未完成稿,欢迎指正 :)