我的頁面名稱是index.php,它包含一些鏈接(內部頁面鏈接)和內容。點擊鏈接我申請"selected" class
鏈接li
並顯示相關內容和我的頁面鏈接從index.php更改爲index.php#c2(或#c3,#c4,其他id的c1)。如何從URL中獲取查詢字符串
我的問題是在頁面加載。如果我在其他頁面給這個鏈接,例如。在page.php
我給這樣的<li><a href="index.php?#c2">link2</a></li>
然後我怎麼可能知道#c2
通過URL在此基礎上我想申請"selected" class
li
。我嘗試了$_SERVER
但未完成。 「?」之後我無法得到字符串。
請告訴我,如果有任何其他的方式做到這一點..
<li class="selected"><a href="#c1">link1</a></li>
<li><a href="#c2">link2</a></li>
<li><a href="#c3">link3</a></li>
<li><a href="#c4">link4</a></li>
<div id="c1"><!-- contents of link1 --></div>
<div id="c2"><!-- contents of link2 --></div>
<div id="c3"><!-- contents of link3 --></div>
<div id="c4"><!-- contents of link4 --></div>
jQuery代碼添加選定類
$('.links a').click(function(){
$('.links a').parent().removeClass('selected');
$(this).parent().addClass('selected');
});
在此先感謝..
重複! http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript - http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery?lq=1 – Undefined 2012-07-19 11:02:03
請參考這個答案 http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a--url-using-javascript – 2012-07-19 11:05:45