Tôi cần lấy id từ url. Vì vậy, nếu url giống như vậy: http://localhost:17241/Chart.aspx?id=11Lấy một số ra khỏi url
Tôi sẽ lấy số 11 làm đầu ra. Nhưng có một id khác nhau trên mọi trang web. Và sau đó tôi sẽ thiết lập chỉ số z với điều đó.
Tôi đã cố gắng để viết một cái gì đó
$.urlParam = function (name) {
var patt1 = new RegExp('[^17241]').exec(window.location.href);
return result[1] || 0;
document.getElementById("link").innerHTML = result;}
Nhưng điều này không làm việc ở tất cả. Có ai biết phải làm gì không?
Vì vậy, bây giờ nó nên thay đổi 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);
});
}
Và nó nên thay đổi z-index của divs
<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>
Cảm ơn
http: // stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript –
@AnoopJoshi Sẽ không hoạt động nếu có nhiều thông số – Tushar
Vì vậy, bạn sẽ làm gì để lấy id của ? https: //jsfiddle.net/wz6bkdn2/1/ –