0

我将脚本的当前主题存储在我的配置文件 (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>";
4

1 回答 1

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>";
于 2012-10-27T11:10:28.230 回答