是什么导致错误“string.split is not a function"? [英] What is causing the error `string.split is not a function`?
本文介绍了是什么导致错误“string.split is not a function"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我会...
未捕获的类型错误:string.split 不是函数
Uncaught TypeError: string.split is not a function
...当我跑步时...
...when I run...
var string = document.location;
var split = string.split('/');
推荐答案
改变这个...
var string = document.location;
这个...
var string = document.location + '';
这是因为 document.location
是一个 位置对象.默认的 .toString()
以字符串形式返回位置,因此串联将触发该位置.
This is because document.location
is a Location object. The default .toString()
returns the location in string form, so the concatenation will trigger that.
您也可以使用 document.URL
得到一个字符串.
You could also use document.URL
to get a string.
这篇关于是什么导致错误“string.split is not a function"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文