您好我有以下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功能和Dropdownlist,因此我可以在它们之间切换。 “Shortmeeting.aspx”默认加载。如果我点击DropDownList中的“EVENT”,我可以从“Shortmeeting.aspx”切换到“Event.aspx”。现在,如果我想切换回“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