3

有什么方法可以判断是否window.location.hash已定义?

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

4

2 回答 2

12
if(window.location.hash) {
    // do stuff!
}
于 2010-11-06T22:50:07.160 回答
2

怎么样:

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

或者

if(typeof window.location.hash !== 'undefined')
{
    //your code
}
于 2010-11-06T22:53:40.107 回答