选择选择输入选项

时间:2014-05-26 11:54:09

标签: html forms

我有多个选项的选择字段:

<option value="lotr">Lord of the Rings</option>
<option value="harry_potter">Harry Potter</option>

提交价值&#34; lotr&#34;或&#34; harry_potter&#34;发送,取决于用户的选择。 但是我不时需要在后端设置选项,包括之前选择的选项。所以我让这些选项看起来像这样:

<option selected="lotr">Lord of the Rings</option>
<option value="harry_potter">Harry Potter</option>

表格显示正确,我可以看到&#34;指环王&#34;在输入中,但是当我尝试提交它时,也有&#34;戒指之王&#34;在params。点是我需要它&#34; lotr&#34;。我不知道我做错了什么,也许还有另一种选择方式吗?

2 个答案:

答案 0 :(得分:2)

你应该将selected =“true”和value =“lotr”设置如下

<option selected="true" value="lotr">Lord of the Rings</option>

答案 1 :(得分:2)

使用此

<option value="lotr" selected >Lord of the Rings</option>
相关问题