what return 'windows.location.pathname'?
what return 'windows.location.pathname'?
我用window. location .pathname函数测试了一些东西。
这是我的js脚本:var location = window.location.pathname;
console.log(location); // -> /de/immobilien-auf-mallorca/
if(location == "/de/immobilien-auf-mallorca"){
console.log('true'); //doesn't work! It is not true???
}else{
console.log('false'); //Output in my console
}
我认为我的var 'location'
是一个字符串,包含这个字符串' /de/immobilien-auf-mallorca
'。
但是如果我包含一个if语句(if location = /de/immobilien-auf-mallorca
),我不进入我的if语句的第一部分。(看上面)
我不知道为什么也许我的变量不是字符串?!
也许有人更了解这个。
谢谢你的帮助!
您选择了一个非常特殊的保留关键字来记录-> location, location默认为window。Location,它是一个对象。解决方案很简单,将变量名替换为类似"myLocation"的东西,这将使技巧。
var myLocation = window.location.pathname;
console.log(myLocation); // -> /de/immobilien-auf-mallorca
if(myLocation == "/de/immobilien-auf-mallorca"){
console.log('true'); //It's going to work....
}else{
console.log('false'); //Output in my console
}
尝试下面的代码:
var locationVar = window.location.pathname;
console.log(locationVar); // -> /de/immobilien-auf-mallorca
if(locationVar == "/de/immobilien-auf-mallorca"){
console.log('true'); //doesn't work! It is not true???
}else{
console.log('false'); //Output in my console
}
相关文章:
- 正在使用$location.path(.)路由ng视图
- Reg-ex,用于解析window.location.pathname并返回个/s
- addClass('active') with window.location.pathname - u
- Javascript - 获取 location.pathname + location.search - 不占用所有部
- window.location.pathname Chrome vs Mozilla
- parent.window.location.pathname 返回未定义
- windows.location.pathname不起作用
- 使用history.pushState()时更新整个location.pathName
- 将location.pathname和location.search一起设置
- 如何“;转换“;window.location.pathname从对象到字符串
- 哪个更快:document.location.pathname或myOwnObj.pathname
- 在location.pathname前添加哈希值
- what return 'windows.location.pathname'?
- 如何使用位置.Href代替location.pathname
- 如何检查数组中的字符串是否在URL/window.location.pathname中
- 如何从window.location.pathname中删除尾部斜杠
- 如何防止window.location.pathname在URL中转义字符
- 如何从window.location.pathname获取文件名
- 相当于NodeJS中的window.location和window.pathname
- # for window.location.pathname