代码之家  ›  专栏  ›  技术社区  ›  Entity

是否定义了Javascript window.location.hash?

  •  3
  • Entity  · 技术社区  · 14 年前

    window.location.hash 定义了吗?

    如果设置了它,那么我将得到变量的值,并使用它在页面上显示额外的内容。

    2 回复  |  直到 14 年前
        1
  •  12
  •   Hamish    14 年前
    if(window.location.hash) {
        // do stuff!
    }
    
        2
  •  2
  •   Alex KeySmith    14 年前

    怎么样:

    if(window.location.hash !== '')
    {
    }
    

    或者

    if(typeof window.location.hash !== 'undefined')
    {
        //your code
    }