已经验证,可供参考!
//用数组给select加options列表项
selectName.options[i]=new options("option_value","option_Text");
selectName.options[i].selected=true;
//例子
<select name="hi" onchange="getSelect('hi');">
<option value="01">一</option>
<option value="02">二</option>
<option value="03">三</option>
<option value="04">四</option>
</select>
//获得value值 如“01”,注意selectedIndex从 0 开始,离开form1访问时要用document.form1.selectName.options[form1.selectName.selectedIndex].value
value = form1.selectName.options[form1.selectName.selectedIndex].value
//获得text值,如“一”
text = form1.selectName.options[form1.selectName.selectedIndex].text
//或
text = form1.selectName.options[form1.selectName.selectedIndex].innerHTML
myOptions = getElementById('hi').options;//得到索引从0开始的值为类似<option value="01">一</option>的数组对象,如要访问value=01的value,还得这样myOptions[0].value
//一个例子:
function comType() {//将从数据库读取的options的value转化成text显示
var comtype = _getObj('company_type').options;
var comtype_db = "{{$comAll.saco_company_type}}";
alert(comtype_db);
for (i=0;i<comtype.length;i++) {
if(comtype[i].value == comtype_db) {
_getObj('saco_company_type').innerHTML = comtype[i].text;
}
}
}