Javascript jQuery中的片段哈希处理
我正在基于文本菜单中的单击事件填充一个名为content的div元素。这很好,但我想处理以下情况:Javascript jQuery中的片段哈希处理,javascript,jquery,html,Javascript,Jquery,Html,我正在基于文本菜单中的单击事件填充一个名为content的div元素。这很好,但我想处理以下情况: 正在刷新URL中带有#片段的页面。目前,它的结果是一个空白div 转到URL中没有#片段的页面时,应显示使用blog.php填充div 提前谢谢 代码 | | | 你可以用几种方法来解决。。也许是这样: // Run on document ready $(function() { // Get hash or set "#blog" as default var hash =
|
|
|
你可以用几种方法来解决。。也许是这样:
// Run on document ready
$(function() {
// Get hash or set "#blog" as default
var hash = document.location.hash || "#blog";
// Trigger click event of anchor that has href as url hash
$('[href="'+hash+'"]').click();
});
// Run on document ready
$(function() {
// Get hash or set "#blog" as default
var hash = document.location.hash || "#blog";
// Trigger click event of anchor that has href as url hash
$('[href="'+hash+'"]').click();
});