String.split() JavaScript 方法在 Firefox 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11030912/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
String.split() JavaScript method is not working in firefox
提问by Muhammad Usman
I am trying to split a string in javascript . it works fine in chrome, but it is not working in firefox
我正在尝试在 javascript 中拆分字符串。它在 chrome 中运行良好,但在 Firefox 中不起作用
code
代码
var a="1#abc";
var b=a.split('#');
The error on cole is TypeError: response.split is not a function
科尔的错误是 TypeError: response.split is not a function
The response in firefox is not in string. It is as [Object XMLDocument]
It is not being converted by toString()
method. HowI can convert it in to string
firefox 中的响应不是字符串。这是因为[Object XMLDocument]
它没有被toString()
方法转换。如何将其转换为字符串
回答by iappwebdev
I don't know what exaclty is happening but you can try to convert your variable into a string before splitting:
我不知道 exaclty 发生了什么,但您可以尝试在拆分之前将变量转换为字符串:
var a="1#abc";
var b=a.toString().split('#');