Dan*_*lik 0 hash jquery equals-operator
我正在使用if条件在jquery和==不适合我也不===。:(这是我的代码:
var hash = window.location.hash;
var hash = hash.replace('#', ' ');
alert(hash); /* Returns abc.*/
if( hash === 'abc'){
alert(hash); /* not coming here.*/
$('.tab').removeClass('is-active');
}
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?提前致谢。
window.location.hash将返回#abc不abc。因此,替换以下代码::
var hash = window.location.hash;
Run Code Online (Sandbox Code Playgroud)
有了这个::
var hash = window.location.hash.split('#')[1];
Run Code Online (Sandbox Code Playgroud)
完整代码将是:
var hash = window.location.hash.split('#')[1];
if( hash === 'abc'){
$('.tab').removeClass('is-active');
}
Run Code Online (Sandbox Code Playgroud)
它会工作。
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |