我在尝试拆分字符串时遇到了一个奇怪的问题,我将其拆分一次并将其保存为变量,但随后我尝试拆分刚刚创建的值,但我不能,它会抛出一个错误提示:无法调用未定义的“split”方法
justName = fullLine.split('(', 1)[0];
dateOne = fullLine.split('(', 2)[1];
dateTwo = dateOne.split(')', 1);
console.log(dateTwo);
如果我注销 justName 那么就没有问题。
fullLine 的一个例子是:
In the Heat of the Night (1967)
最佳答案
我可以看到它正在工作。在这里检查这个 jsFiddle。
<div id="a"></div>
<input type="button" onclick="abc()" value="Split" />
function abc(){
var fullLine="hello(world)Qwerty";
justName = fullLine.split('(', 1)[0];
dateOne = fullLine.split('(', 2)[1];
dateTwo = dateOne.split(')', 1);
alert(dateTwo);
}
关于JavaScript split 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374801/