JQuery select 编程时选中原有的值

js 此为核心代码

$(document).ready(function(){
$("#carTypeId").attr("value",'${carInfo.carTypeId}'); //后台传递的值
})

<tr>
<th width="20%">车辆种类名称: </th>
<td>
<%-- <input type="text" id="carTypeId" name="carTypeId" value="${carInfo.carTypeId}" class="inputText" validate="{required:false,number:true,maxIntLen:10}" />
--%>
<select name="carTypeId" id ="carTypeId" class="select panel-search-inputText">
<option value="">--选择--</option>
<c:forEach items="${listCarType}" var="keyword" varStatus="id">
<option value="${keyword.id}" <c:if test="${keyword.id} == ${carInfo.carTypeId}">selected</c:if>> ${keyword.typeName} </option>
</c:forEach>
</select>
</td>

java 代码

List<CarType> listCarType=carTypeService.getAll();
return getAutoView().addObject("carInfo",carInfo !=null?carInfo:null)
.addObject("listCarType", listCarType)

猜你喜欢

转载自www.cnblogs.com/1880su/p/10172159.html