1,js操作下拉列表框当前所选值
复制代码 代码示例:
function setSelectOption(objId, targetValue){
//objid:下拉列表框的ID;targetValue:当前所选值
var obj = document.getElementById(objId);
if(obj){
var options = obj.options;
if(options){
var len = options.length;
for(var i=0;i<len;i++){
if(options[i].value == targetValue){
options[i].defaultSelected = true;
options[i].selected = true;
return true;
}
} // www.jb200.com
} else {
alert('missing element(s)!');
}
} else {
alert('missing element(s)!');
}
}
2,设置下拉列表框的当前选择项(option)
复制代码 代码示例:
<select>
<option value="1" <%if(sesssionValue==1){%> selected="selected"<%}%>>1:b </option>
<option value="2" <%if(sesssionValue==2){%> selected="selected"<%}%>>2:b </option>
<option value="3" <%if(sesssionValue==3){%> selected="selected"<%}%>>3:c </option>
<option value="4" <%if(sesssionValue==4){%> selected="selected"<%}%>>4:d </option>
</select>