不看你的擴展插件的細節,這裏是我在我自己的一個網站最近使用的解決方案。希望您可以自定義使用您正在使用的擴展器插件。我無法承擔變量解析的功勞,這起源於其他地方。
您的鏈接將需要設置爲這樣:
http://jjnursingnotes.com/NOV12?section=01
然後你的JavaScript:
<script type="text/javascript">
// Redirect to Appropriate Section
var urlParams = {};
(function() {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
$(document).ready(function(){
if (urlParams['section'] != '') {
// urlParams['section'] variable = the ?section=XXX part of URL
// Here is where you would need integration with expanding box
// Assuming you use something like <div class="expander" id="sect01">
// as your expander, something to this effect ought to work:
$("#sect" + urlParams['section']).find(".read-more a").click();
// Position document at start of anchor
$('body,html').animate({ scrollTop: $("#sect" + urlParams['section']).offset().top }, 500);
}
});
</script>
是的,只要找到與給定的名稱(從'window.location的拉錨標記。散列「),遍歷它的父項,並展開它。 –