我想显示选择的值。在文本字段中,我可以将其显示在如下所示的值内
value ="<%=event_data.getE_venue()%>"
代码:
<input type="text" name="where" placeholder="Add a place" size="23" value ="<%=event_data.getE_venue()%>"/> <select name="category" value ="<%=event_data.getE_target_category()%>" id="single1"> <option>Sports</option> <option>Corporate</option> <option>Religious</option> <option>Music</option> </select>
但在下拉框中它不起作用。请帮我。谢谢..
首先,select不能以这种方式工作,您需要将selected属性放入与您的输入匹配的option中。
例如: <option selected='selected'>Sports</option>
<option selected='selected'>Sports</option>
检查这个小提琴:
http://jsfiddle.net/ZLTS7/
您的代码应类似于:
<input type="text" name="where" placeholder="Add a place" size="23" value ="<%=event_data.getE_venue()%>"/> <select name="category" id="single1"> <option <%= (event_data.getE_target_category().equals("Sports")?"selected='selected'":"") %>>Sports</option> <option <%= (event_data.getE_target_category().equals("Corporate")?"selected='selected'":"") %>>Corporate</option> <option <%= (event_data.getE_target_category().equals("Religious")?"selected='selected'","") %>>Religious</option> <option <%= (event_data.getE_target_category().equals("Music")?"selected='selected'":"") %>>Music</option> </select>