为什么我越来越...
未捕获的 TypeError:string.split 不是函数
...当我跑步时...
var string = document.location;
var split = string.split('/');
为什么我越来越...
未捕获的 TypeError:string.split 不是函数
...当我跑步时...
var string = document.location;
var split = string.split('/');
改变这个...
var string = document.location;
对这个……
var string = document.location + '';
这是因为document.location
它是一个Location 对象。默认.toString()
以字符串形式返回位置,因此连接将触发该位置。
你也可以document.URL
用来获取字符串。
也许
string = document.location.href;
arrayOfStrings = string.toString().split('/');
假设你想要当前的 url
运行这个
// you'll see that it prints Object
console.log(typeof document.location);
你想要document.location.toString()
或document.location.href
document.location
不是字符串。
您可能想要使用document.location.href
ordocument.location.pathname
代替。
在分句 if 中,使用()
. 例如:
stringtorray = "xxxx,yyyyy,zzzzz";
if (xxx && (stringtoarray.split(',') + "")) { ...