0

这里的逻辑很简单,我不知道如何将值与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
    }
4

1 回答 1

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

if(val.length) {  // val
  // do something
} else {
  // do something else
}
于 2012-06-27T01:07:19.470 回答