-1

我有一个问题,我有一个选择框,但是如何显示选定的值?

<select name="please">
     <option value="<% $lcost.sup %>">Super</option>
     <option value="<% $lcost.supp %>">Super Plus</option>
     <option value="<% $lcost.supe %>">Super E 10</option>
     <option value="<% $lcost.lpg %>">LPG</option>
     <option value="<% $lcost.diesel%>">Diesel</option>
     </select>

请帮忙 ;)

4

2 回答 2

1
suppose if @object is the form object and 'car' is the attribute then you should put condition on each option tag: ---

<select name="please">
     <option value="<% $lcost.sup %>" "<% @object.car == $lcost.sup ? 'selected' : '' %>">Super</option>
     <option value="<% $lcost.supp %>" "<% @object.car == $lcost.supp ? 'selected' : '' %>">Super Plus</option>
     <option value="<% $lcost.supe %>" "<% @object.car == $lcost.supe ? 'selected' : '' %>">Super E 10</option>
     <option value="<% $lcost.lpg %>" "<% @object.car == $lcost.lpg ? 'selected' : '' %>">LPG</option>
     <option value="<% $lcost.diesel%>" "<% @object.car == $lcost.diesel ? 'selected' : '' %>">Diesel</option>
     </select>

阅读 HTML 文档以在选择框中显示选定的值。 http://www.w3schools.com/tags/att_option_selected.asp

于 2013-07-08T13:48:42.157 回答
0

设置“选定”的 html 属性

<select name="please">
 <option value="<% $lcost.sup %>" selected="selected">Super</option>
 <option value="<% $lcost.supp %>">Super Plus</option>
 <option value="<% $lcost.supe %>">Super E 10</option>
 <option value="<% $lcost.lpg %>">LPG</option>
 <option value="<% $lcost.diesel%>">Diesel</option>
</select>

这将选择第一个选项

于 2013-07-08T13:39:24.577 回答