我需要在初始页面加载时运行一些函数,如果 url 包含特定的哈希值,也需要刷新页面。
到目前为止,我只能在页面刷新时让它工作,而在我第一次进入页面时却无法工作。
我的代码:
$(document).ready(function() {
if (document.location.href.indexOf('#story') > -1) {
alert('true');
}
});
Run Code Online (Sandbox Code Playgroud)
你应该window.location.hash像这样工作:
$(document).ready(function() {
if (window.location.hash === '#story') {
alert('true');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1216 次 |
| 最近记录: |