c# - 使用下拉菜单在两个页面之间切换

标签 c# javascript asp.net drop-down-menu

嗨,我有以下 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;

        }

下拉列表:

<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”。如果我单击 DropDownList 中的“EVENT”,我可以从“Shortmeeting.aspx”切换到“Event.aspx”。现在,如果我想切换回“Shortmeeting.aspx”,为此我单击 DropDownList 中的“SHORT”,但它不起作用。

如何在这两个页面之间正确切换?请帮忙

最佳答案

只需删除 value 中的空白

Value="简短 session "

     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

关于c# - 使用下拉菜单在两个页面之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13510901/

相关文章:

c# - 签署 winforms exe 时出现加密失败 - "The Parameter is incorrect"

javascript - 使用 jQuery 导航 <tr> 中的数据

c# - 授予ASPNETDB.MDF SQL DB IIS_IUSRS权限

c# - UWP - 按下空格时不要触发 Click 事件(就像在电影和电视应用中一样)

c# - Roslyn - 更改 SyntaxToken 或 SyntaxNode 的 TextSpan

javascript - 在簇的顶部放置标记; z-index 不工作

asp.net - HttpRuntime.Cache 在哪里存储数据?

mysql - 我在 mysql 中遇到错误,例如命令 ="SELECT * FROM subjects WHERE Course LIKE (' %'+ ? + ' %')

c# - 不同线程中的渲染控制

javascript倒计时显示天数?