2012-08-09 53 views
-1
<div> 
<select name="mySelect" id="mySelect" class="select" onchange="if(this.options[this.selectedIndex].value != ''){window.top.location.href=this.options[this.selectedIndex].value}"> 
<option value="english.php">English</option> 
<option value="french.php">French</option> 
<option value="spanish.php">Spanish</option> 
</select> 
</div> 

我要改變語言它做工精細,當我改變語言,但在下拉菜單中總是顯示英文得到選擇的值在選擇標籤

回答

2

一個selected屬性添加到您想要的選項被選擇時頁面加載。

+0

但選定的屬性將只選擇該值..但我想顯示該值,我選擇了喜歡如果選擇英文頁面加載它將選擇英語,如果我選擇西班牙語,它會顯示西班牙語在下拉列表中。 – Nav 2012-08-09 05:57:35

+0

@Nav - 將選定的屬性放在th上英語選項english.php。將所選屬性放在spanish.php的西班牙語選項上。等等 – Quentin 2012-08-09 06:09:07

1

您需要添加另一個空白的標籤。

工作例如: http://jsfiddle.net/XYSXA/

<select name="mySelect" id="mySelect" class="select" onchange="if(this.options[this.selectedIndex].value != ''){window.top.location.href=this.options[this.selectedIndex].value}"> 
    <option value=""></option> 
    <option value="english.php">English</option> 
    <option value="french.php">French</option> 
    <option value="spanish.php">Spanish</option> 
</select>​ 

此選項的方式沒有人會被默認選中。

或者,您可以使用設置屬性selected在開頭<option>標記之一內指定默認應選擇哪種語言。例如,通過默認選擇法語:

<select name="mySelect" id="mySelect" class="select" onchange="if(this.options[this.selectedIndex].value != ''){window.top.location.href=this.options[this.selectedIndex].value}"> 
    <option value=""></option> 
    <option value="english.php">English</option> 
    <option value="french.php" selected>French</option> 
    <option value="spanish.php">Spanish</option> 
</select>​ 

工作例如:http://jsfiddle.net/XYSXA/1/

0
<? 
$file=basename($_SERVER['PHP_SELF'],".php"); 
$file=ucwords($file); 
?> 
<option value="french.php" <?=($file=="French")?" selected='selected'":""?>>French</option> 

我爲假設你正在使用的格式,如:法國的french.php,西班牙文spanish.php等