2
我注意到在JSURL哈希古怪
一些奇怪的行为window.location.hash = '';
var hash = window.location.hash;
alert(hash + ' = ' + hash.length);
//outputs: ' = 0'
window.location.hash = '#';
hash = window.location.hash;
alert(hash + ' = ' + hash.length);
//outputs: ' = 0'
window.location.hash = '_';
hash = window.location.hash;
alert(hash + ' = ' + hash.length);
//outputs: '_ = 2'
基本上我想要触发三个条件
- 没有哈希
- 只是凑
- 哈希文本
然而它看起来像J S没有看到example.com/和example.com/# 之间的区别此外,我不知道如何完全删除哈希。
任何帮助?
所以不存在hash.length = 1的情况 – Moak 2010-10-08 05:53:15
否 - 它将包含散列字符('#'),如果它是空的或者只有散列字符(与浏览器相同),则它报告0,而不管。 – mway 2010-10-08 05:54:44
@Moak,这是正确的。你也无法判断'window.location.hash =='#''。它对''和'#'都返回false。 – helloandre 2010-10-08 05:58:20