我有一张表,我在其中保存类别和产品名称:
+-----------------------+ | products | +-----------------------+ | id name cat_name | | 1 lily flower | | 2 hibiscus flower | | 3 cat animal | | 4 dog animal | +-----------------------+
I want to have a select list with first cat_name and inside that product 'name'
**flower**
-lily
-hibiscus
**animal**
-cat
-dog
如何在选择列表中实现这一点。请帮忙。
最佳答案
在 html 正文中,它是对选项进行分组的 optgroup 标记。
<select>
<optgroup label="flower">
<option value="whatever">lily</option>
<option value="whatever">hibiscus</option>
</optgroup>
...
</select>
希望你明白了。 请注意,这些 optgroups 看起来很差。也许你还需要一些 jquery 插件来获得你想要的东西。
关于php如何在选择下拉列表中显示类别然后显示子类别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31758133/