JQuery删除字符串中包含一些单词的反斜杠
我的字符串是“\upload\document\file.txt”,我想用jQuery删除该字符串中的“\upload”部分。我尝试了这个,但不起作用:JQuery删除字符串中包含一些单词的反斜杠,jquery,Jquery,我的字符串是“\upload\document\file.txt”,我想用jQuery删除该字符串中的“\upload”部分。我尝试了这个,但不起作用: var filePath=“\upload\document\file.txt”; filePath=filePath.replace('\upload',''); log(文件路径)您需要转义\ var filePath=“\\upload\\document\\file.txt”; filePath=filePath.replace('
var filePath=“\upload\document\file.txt”;
filePath=filePath.replace('\upload','');
log(文件路径)代码>您需要转义\
var filePath=“\\upload\\document\\file.txt”;
filePath=filePath.replace('\\upload','');
console.log(文件路径)
您需要转义\
var filePath=“\\upload\\document\\file.txt”;
filePath=filePath.replace('\\upload','');
console.log(filePath)
问题在于字符串开头的\u
被解释为Unicode。因此,您在控制台中看到了错误
要避免此问题,您需要使用\\
来转义字符串中的单个斜杠:
var filePath=“\\upload\\document\\file.txt”;
filePath=filePath.replace('\\upload','');
log(文件路径)代码>问题是因为字符串开头的\u
被解释为Unicode。因此,您在控制台中看到了错误
要避免此问题,您需要使用\\
来转义字符串中的单个斜杠:
var filePath=“\\upload\\document\\file.txt”;
filePath=filePath.replace('\\upload','');
log(文件路径)代码>的可能重复项的可能重复项