我的配置文件中存储了我的脚本的当前主题(JQUERY_THEME)如何在下拉列表中创建预选值。
$jquerytheme = JQUERY_THEME;
$themes = array("base", "black-tie", "blitzer", "cupertino", "dark-hive", "dot-luv", "eggplant", "excite-bike", "flick", "hot-sneaks", "humanity", "le-frog", "mint-choc", "overcast", "pepper-grinder", "redmond", "smoothness", "south-street", "start", "sunny", "swanky-purse", "trontastic", "ui-darkness", "ui-lightness", "vader");
echo "<p><select name=\"jquerytheme\">";
foreach ($themes as $value) {
echo "<option value=\"$value\">". ucfirst($value) . "</option>";
}
echo "</select></p>";
答案 0 :(得分:1)
如果您想要预先选择一个选项,则必须使用选项中的selected
属性:
echo "<p><select name=\"jquerytheme\">";
foreach ($themes as $value) {
$selected = ($value == $jquerytheme) ? 'selected="selected"' : '';
echo "<option $selected value=\"$value\">". ucfirst($value) . "</option>";
}
echo "</select></p>";