2011-03-13 89 views
1
當前頁面

我有一個選擇的形式是這樣的:默認選項對應

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

如何添加屬性selected='selected'對應於使用jQuery當前頁面的選項?

+0

您標記的jQuery UI的改變?我在你的問題中沒有看到它? – Rafay 2011-03-13 20:50:04

+0

我正在使用它來蒙皮選擇元素。 – AKor 2011-03-13 20:52:15

回答

2

我認爲最好是使用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>'; 

要根據默認頁面

+0

我認爲一個開關會更好,並選擇=「選擇」將使代碼驗證:) – 2011-03-13 20:57:20

+1

我同意此:) – 2011-03-13 20:59:13

0

您正在使用哪種服務器端腳本語言?我會猜測PHP,但那是我唯一熟悉的。爲什麼在動態創建頁面時使用jquery?

+0

我只是認爲jQuery最容易使用,是的,我使用PHP。 – AKor 2011-03-13 20:46:02