【发布时间】:2010-10-08 05:47:58
【问题描述】:
我注意到 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/ 之间的区别# 我也不知道如何完全删除哈希。
有什么帮助吗?
【问题讨论】:
标签: javascript url fragment-identifier