除了jQuery中的特定url之外的hash替换

时间:2014-10-28 21:15:12

标签: javascript jquery

我有一个哈希替换了jQuery来处理我的手风琴。

var hash = window.location.hash;
var _hash = hash.replace(/#/, '');

但是,我的导航中还有一个哈希链接(/ hello#let-us)滚动到id = let-us的div。如何更改上面的jQuery来过滤哈希替换(替换除'/ hello#let-us'之外的所有哈希链接)?

1 个答案:

答案 0 :(得分:0)

只需检查_hash的结果...如果使用了jQuery,那么http://api.jquery.com/jquery.inarray/

var toCheck = ['let-us', 'another-value'];
if ($.inArray(_hash, toCheck) == -1) {
 // hash is not in array toCheck
}