所以我有一個頁面有3個按鈕來過濾頁面上的內容。使用網址哈希執行點擊事件
<section class="solution-filter">
<div class="wrapper">
<button class="fact-sheet" data-target_category="fact-sheet" disabled="">Fact sheet</button>
<button class="demo" data-target_category="demo">Demo</button>
<button class="apps" data-target_category="apps">Apps and connectors</button>
</div><!-- /.wrapper -->
</section>
我希望能夠執行一個按鈕點擊取決於URL散列。
例如http://example.com/#demo 將在<button class="demo" data-target_category="demo">Demo</button>
if (window.location.hash) {
$(document).click($('<button>').data('target_category', (window.location.hash));
}
看起來你已經做到了。有什麼問題 ? –
你可能只是想聽'hashchange'事件? – adeneo