我在HTML / JS中有以下代码:
<a href="#customer_tickets" class="tabLink" onclick="LoadPage('/customer/editcustomer_tickets.php?customer=<?php echo $customer["sequence"]; ?>', '.EditCustomer');">Tickets</a>
if(location.hash) {
//load the set hash here
}
单击a href时,它将运行JS中的LoadPage函数以将页面加载到div中
单击它们时,它将在浏览器的URL中设置哈希位置
我希望能够检查页面加载时是否设置了哈希位置,如果已设置,则自动单击正确的href
我怎样才能做到这一点?
使用的值location.hash
来标识正确的a
元素,然后单击它:
//Wait for the document to be ready
$(function() {
//Check if we have a hash, if so try to click an element that links to it
if (location.hash.length > 0) {
$('a[href="' + location.hash + '"]').click();
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句