|
函数体如下:
//------select options control----- function addOptions(selectId, arrValue, arrText){ try{ for(i = 0, arrLen = arrValue.length; i < arrLen; i++){ if(arrText[i] != "" && arrValue[i] != ""){ $(selectId).options.add( new Option(arrText[i], arrValue[i]) ); } } }catch(e){} } //添加option
function clearOptions(selectId){ try{ $(selectId).options.length=0; }catch(e){} } //清楚option
function setSelected(selectId, index){ try{ $(selectId).options[index].selected = true; }catch(e){} } //根据序号设置选项选中
function setSelectedByValue(selectId, selectValue){ try{ for(var i=0; i<$(selectId).options.length; i++ ){ if($(selectId).options[i].value == selectValue){ $(selectId).options[i].selected = true; }else{ $(selectId).options[i].removeAttribute("selected"); } } }catch(e){} } //根据option的value值设置选项选中
function getSelectValue(selectId){ try{ return $(selectId).options[$(selectId).selectedIndex].value; }catch(e){return null;} } //获取选中的选项的value值
function getSelectText(selectId){ try{ return $(selectId).options[$(selectId).selectedIndex].text; }catch(e){return null;} } //获取选中选项的text值
|