我注意到 JS 中有一些奇怪的行为
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'
基本上我想触发三个条件
- 没有哈希
- 只是哈希
- 带文本的哈希
但是似乎 JS 没有看到 example.com/ 和 example.com/# 之间的区别我也不知道如何完全删除哈希。
有什么帮助吗?