2012-11-22 63 views
1

嗨兩個頁面之間切換,我有以下的javascript和DropDownList的:使用下拉菜單

function loadanlasstyp(ddl) { 
      var ControlName = document.getElementById(ddl.id); 

      if (ControlName.value == "Event") { 
       window.location = "../book/event.aspx"; 

      } 

      else if (ControlName.value == "Short Meeting") { 
       window.location = "../book/shortmeeting.aspx"; 
      } 
      return true; 

     } 

的DropDownList:

<asp:DropDownList ID="ddlAnlasstyp" runat="server" CssClass="ff" Height="21px" onChange="javascript:loadanlasstyp(this)" 
         TabIndex="3" Width="150px"> 
         <asp:ListItem Value="Short meeting">Short</asp:ListItem> 
         <asp:ListItem Value="Event">Event</asp:ListItem> 
</asp:DropDownList> 

我的JavaScript功能和下拉列表上的兩個頁面,從而使我可以在它們之間切換。 「Shortmeeting.aspx」正在默認加載。我可以從「Shortmeeting.aspx」切換到「Event.aspx」,如果我點擊DropDownList中的「EVENT」。現在,如果我想切換回「Shortmeeting.aspx」,爲此我點擊DropDownList中的「SHORT」,但它不起作用。

如何正確地在這兩頁之間切換?請幫助

+0

區分大小寫 「短會」 和「短會 –

回答

1

只需卸下空的空間價值

值= 「短會」

 to 

值= 「短」

else if (ControlName.value == "Short") { 
      window.location = "../book/shortmeeting.aspx"; 
     } 

空空間做字符串時產生問題,有時匹配比較。您可以創建一個字符串比較函數供將來參考。

function strcmp(a, b) { 
if (a.toString() < b.toString()) return -1; 
if (a.toString() > b.toString()) return 1; 
return 0; 

}

function strcmp(a, b) { 
    a = a.toString(), b = b.toString(); 
    for (var i=0,n=Math.max(a.length, b.length); i<n && a.charAt(i) === b.charAt(i); ++i); 
    if (i === n) return 0; 
    return a.charAt(i) > b.charAt(i) ? -1 : 1; 
} 

看到這個鏈接引用link

+0

這就是問題-.-。感謝您的幫助! – Paks

+0

你歡迎.... [沙茲] – Shaz