日期:2014-05-16  浏览次数:20291 次

jsp页面中select下拉控件设置默认值。
1.普通的select:
<td align="right" >结算方式:</td>
<td align="left" >
<select name="balanceWay"  id="balanceWay" onmouseover="" class="otextcss">
<option value="0">请选择</option>
<option value="1">一票制</option>
<option value="2">两票制</option>
<option value="3">其他</option>
</select>
<script>
frm.balanceWay.value = "<c:out value='${tradeAgreement.balanceWay}'/>" </script>
</td>

可以用上面这种js的方式设置默认值为查询出来的tradeAgreement对象的balanceWay值




2.struts里 select和option都是动态取到的
<tr class="common">
<td align="right" 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>