开发者

Default option on a select form corresponds to current page

I have a select form lik开发者_JAVA百科e this:

echo "<option value='../profile'>Saves</option>";
echo "<option value='../notifications' selected='selected'>Notifications</option>";
echo "<option value='../settings'>Settings</option>";

How can I add the attribute selected='selected' to the option corresponding to the current page using jQuery?


I think it is better to use php.

$selected1 = ($_GET['page'] == 'profile') ? 'selected' : null;
$selected2 = ($_GET['page'] == 'notif') ? 'selected' : null;
$selected3 = ($_GET['page'] == 'settings') ? 'selected' : null;

echo '<option value="../profile" '.$selected1.'>Saves</option>';
echo '<option value="../notifications" '.$selected2.'>Notifications</option>';
echo '<option value="../settings" '.$selected3.'>Settings</option>';

To change according to the default page


what server side scripting language are you using? I would guess php but thats the only one I'm familiar with. Why use jquery when you creating your page dynamically?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜