jsp页面中select下拉控件设置默认值。
1.普通的select:
<td align="right" >结算方式:</td>
<td align="left" >
<select name="balanceWay" id="balanceWay" onmouseover="" width="8%">所属库:</td>
<td align="left" width="20%">
<html:select styleId="warehouse_id" name="cameraOperateForm" property="warehouseid" style="width:220" value="warehouse_id.name">
<html:options collection="warehouses" labelProperty="name" property="id" />
</html:select>
<script>
document.getElementById("warehouse_id").value="${cameraOperateForm.warehouse_id.id}";</script>
<font color="red">*</font>
</td>
</tr>
这里也是通过js把value设为对应的id。因为property为id值。
其中的script也可以改成:
<script>
for(var i=0;i<document.getElementById('balanceWay').options.length;i++){
if(document.getElementById(balanceWay).options[i].value==='${cameraOperateForm.proid}'){
document.getElementById('balanceWay').options[i].selected=true;
}
}
</script>