【发布时间】:2015-05-27 12:14:23
【问题描述】:
我需要从 url 中获取 id。 所以如果网址是这样的:http://localhost:17241/Chart.aspx?id=11
我应该得到数字 11 作为输出。 但是每个站点都有不同的 id。之后,我将使用它设置 z-index。
我已经尝试写一些东西了
$.urlParam = function (name) {
var patt1 = new RegExp('[^17241]').exec(window.location.href);
return result[1] || 0;
document.getElementById("link").innerHTML = result;}
但这根本不起作用。 有谁知道该怎么做?
所以现在它应该改变 z-index:
var url = window.location.href;
var params = url.split('?');
var id = params[1].split('=')[1]; //params[1] will contain everything after ?
console.log(id);
if(id == 11)
{
$(“#one”).each(function() {
$(this).css(“z-index“, 0);
});
}
else if(id == 31)
{
$(“#four”).each(function() {
$(this).css(“z-index“, 0);
});
}
它应该改变 div 的 z-index
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<div class="contentwidth" id="chartdiv">
<asp:Label ID="lblStatus" runat="server"></asp:Label>
<div id="one" style="position: absolute; top: 0; left: 0; height: 100%; width: 100%;">
<asp:Literal ID="ltrRenderChart" runat="server"></asp:Literal>
</div>
<div id="two" style="position: absolute; top: 0; left: 50%; height: 100%; width: 100%; z-index:-1">
<asp:Literal ID="ltrRenderChart2" runat="server"></asp:Literal>
</div>
<div id="three" style="position: absolute; top: 50%; left: 0; height: 100%; width: 100%; z-index:-1">
<asp:Literal ID="ltrRenderChart3" runat="server"></asp:Literal>
</div>
<div id="four" style="position: absolute; top: 50%; left: 50%; height: 100%; width: 100%; z-index:-1 ">
<asp:Literal ID="ltrRenderChart4" runat="server"></asp:Literal>
</div>
</div>
谢谢
【问题讨论】:
-
@AnoopJoshi 如果有很多参数将不起作用
-
那么你会怎么做才能得到 的 id 呢?jsfiddle.net/wz6bkdn2/1
-
为什么不直接将服务器端的id值输出到javascript中呢?
-
@Perplexor 我已经尝试在 c# 中执行此操作,因为我有一个 if-else 并且我使用了脚本管理器。但我做不到。
标签: javascript jquery regex