URLアドレスにハッシュ(#)を取得するページがあります。 localhost:15164/L3/mobile /#Android/Alcateljqueryを使用してURLからハッシュ(#)を取得し、ページロードで使用する方法
jqueryを使用してURLアドレスを取得し、それをコードの後ろのページのloadイベントで使用したいとします。
<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>
ページロード(jqueryのからアドレスを取得する):
protected void Page_Load(object sender, EventArgs e)
{
urlLable.DataBind();
string urlStr = urlLable.Text;
Response.Write(urlStr);
}
[の可能性のある重複の外にアンカーを解析するための最も簡単な方法は何現在のページの場所?](http://stackoverflow.com/questions/693844/whats-the-easiest-way-to-parse-the-anchor-out-of-the-current-pages-location) –