简体   繁体   English

如何使用jquery从URL获取哈希(#)之后的值并在页面加载中使用

[英]How do I get the value after hash (#) from a URL using jquery and use in page load

i have a page that get url address with hash(#): localhost:15164/L3/mobile/#Android/Alcatel 我有一个页面,该页面的URL地址带有哈希值(#):localhost:15164 / L3 / mobile /#Android / Alcatel

i want to get url address with jquery and use it on page load event in code behind. 我想用jQuery获取URL地址,并在后面的代码中的页面加载事件中使用它。

<head runat="server">
    <title></title>
    <script src="js/jquery1.8.2.js"></script>
        <script>
            $(document).ready(function () {

                var url = window.location.href;
                var rest = url.substring(url.lastIndexOf("#") + 1, url.length);
                $('#urlLable').text(rest); 

        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="urlLable" runat="server" Text="Label"></asp:Label>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>

page load ( to get address from jquery): 页面加载(从jquery获取地址):

protected void Page_Load(object sender, EventArgs e)
        {
            urlLable.DataBind();
            string urlStr = urlLable.Text;
            Response.Write(urlStr);
        }

哈希在这里可用:

location.hash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM