是什么导致错误`string.split不是函数`? [英] What is causing the error `string.split is not a function`?

查看:185
本文介绍了是什么导致错误`string.split不是函数`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我会...


未捕获TypeError: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不是函数`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆