我在select中有四个值,在数据库中可能只有两个值存储在它们中。
<select id="notebboktype" name="notebooktype">
<option value="Convertible 2 in 1">Convertible 2 in 1</option>
<option value="Notebook">Notebook</option>
<option value="Laptop">Laptop</option>
<option value="Ultrabook">Ultrabook</option>
</select>
我如何获得选定的价值。我试过这个:
<option value="Convertible 2 in 1" <?php if ($row['notebooktype'] == "Convertible 2 in 1") echo 'selected = "selected"'; ?>>Convertible 2 in 1</option>
<option value="Notebook" <?php if ($row['notebooktype'] == 'Notebook') echo 'selected = "selected"'; ?>>Notebook</option>
<option value="Ultrabook" <?php if ($row['notebooktype'] == 'Ultrabook') echo 'selected = "selected"'; ?>>Ultrabook</option>
<option value="laptop" <?php if ($row['notebooktype'] == 'laptop') echo 'selected = "selected"'; ?>>laptop</option>
但它仍然只给我第一个值。
答案 0 :(得分:0)
您需要使用
multiple
多个<select id="notebboktype" name="notebooktype"
中的
>
属性
无需回复选择=&#34;已选择&#34; 只是回显已选择
<select id="notebboktype" name="notebooktype" multiple>
<option value="Convertible 2 in 1">Convertible 2 in 1</option>
<option value="Notebook">Notebook</option>
<option value="Laptop">Laptop</option>
<option value="Ultrabook">Ultrabook</option>
</select>
答案 1 :(得分:0)
<select id="notebboktype" name="notebooktype" multiple>
<option value="Convertible 2 in 1">Convertible 2 in 1</option>
<option value="Notebook">Notebook</option>
<option value="Laptop">Laptop</option>
<option value="Ultrabook">Ultrabook</option>
</select>
<select id="notebboktype" name="notebooktype" multiple>
<option value="Convertible 2 in 1" <?php if ($row['notebooktype'] == "Convertible 2 in 1") echo 'selected'; ?>>Convertible 2 in 1</option>
<option value="Notebook" <?php if ($row['notebooktype'] == 'Notebook') echo 'selected'; ?>>Notebook</option>
<option value="Ultrabook" <?php if ($row['notebooktype'] == 'Ultrabook') echo 'selected'; ?>>Ultrabook</option>
<option value="laptop" <?php if ($row['notebooktype'] == 'laptop') echo 'selected'; ?>>laptop</option>
</select>
答案 2 :(得分:0)
这是..
<option value="Convertible 2 in 1" <?php if ($row['notebooktype'] == "Convertible 2 in 1") { echo ' selected = "selected"'; } ?> >Convertible 2 in 1</option>
<option value="Notebook" <?php if ($row['notebooktype'] == 'Notebook') { echo ' selected = "selected"'; } ?> >Notebook</option>
<option value="Ultrabook" <?php if ($row['notebooktype'] == 'Ultrabook') { echo ' selected = "selected"'; } ?> >Ultrabook</option>
<option value="laptop" <?php if ($row['notebooktype'] == 'laptop') { echo ' selected = "selected"'; } ?> >laptop</option>