jQuery如果hash有附加值

时间:2012-06-27 01:03:00

标签: jquery hash split

这里的简单逻辑,我不知道如何将值与window.location.hash返回的哈希值分开。像.split('=')[0]这样的东西,但是除去之后的所有内容,而不是之后的所有内容。

一些潜在的哈希值:/#work /#work=video1

我想说:

var hash = window.location.hash,
    val  = hash.split('=')[0];

    if (val != ''){
        do some stuff because there IS a value
        i.e. once split, the value is something
    } else {
        do some other stuff because there IS a value
        i.e. once split, the value is nothing
    }

1 个答案:

答案 0 :(得分:0)

var hash = window.location.hash,
    val  = hash.substr( hash.indexOf('=') + 1 );

if(val.length) {  // val
  // do something
} else {
  // do something else
}