Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery中的片段哈希处理_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery中的片段哈希处理

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 =

我正在基于文本菜单中的单击事件填充一个名为content的div元素。这很好,但我想处理以下情况:

  • 正在刷新URL中带有#片段的页面。目前,它的结果是一个空白div
  • 转到URL中没有#片段的页面时,应显示使用blog.php填充div
  • 提前谢谢

    代码

    
    |
    |
    |
    
    你可以用几种方法来解决。。也许是这样:

    // 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();
    });