2012-06-27 14 views
0

這裏的簡單邏輯,我不知道我怎樣才能將這個值與由window.location.hash返回的散列分開。像.split('=')[0],但刪除它之前的一切,而不是它後面的一切。jQuery如果散列有一個附加值

一些潛在的哈希值:/#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 
    } 

回答

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

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

這僅獲得第一位的,怎麼樣,如果他們有多個值嗎? –