根据数据库信息设置默认颜色 ,${bean.color}是后台传过来的value值;color对应的是select的id
jquery代码如下:
$("#color option[value=${bean.color}]").attr("selected", "selected");
select代码:
<select name="color" id="color" style="width: 120px;">
<option value="Black" style="background-color: Black;color: #FFFFFF;">黑色</option>
<option value="Gray" style="background-color: Gray;">灰色</option>
<option value="Blue" style="background-color: Blue;color: #FFFFFF;">蓝色</option>
<option value="DeepSkyBlue" style="background-color: DeepSkyBlue;">天蓝色</option>
<option value="Purple" style="background-color: Purple;color: #FFFFFF;">紫色</option>
<option value="DeepPink" style="background-color: DeepPink;">深粉色</option>
<option value="Violet" style="background-color: Violet;">紫罗兰色</option>
<option value="Pink" style="background-color: Pink;">粉红色</option>
<option value="LimeGreen" style="background-color: LimeGreen;color: #FFFFFF;">酸橙绿</option>
<option value="Green" style="background-color: Green;color: #FFFFFF;">绿色</option>
<option value="YellowGreen" style="background-color: YellowGreen;">黄绿色</option>
<option value="Orange" style="background-color: Orange;">桔×××</option>
<option value="Red" style="background-color: Red;">红色</option>
<option value="Brown" style="background-color: Brown;">褐色</option>
<option value="BurlyWood" style="background-color: BurlyWood;">木色</option>
</select>