我在第一个逗号处继续收到此错误“SyntaxError:syntax error”,我应该更改什么才能使其正常工作?
if (location.pathname.replace(/^//,'') == this.pathname.replace(/^//,'') && location.hostname == this.hostname)
答案 0 :(得分:1)
您需要在正则表达式中转义正斜杠
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname)
答案 1 :(得分:1)
这是双斜线,
if (location.pathname.replace(/^/,'') == this.pathname.replace(/^/,'') && location.hostname == this.hostname)
答案 2 :(得分:0)
使用RegExp
构造函数
var regexp = new RegExp("^/", "");
if (location.pathname.replace(regexp,'') == this.pathname.replace(regexp,'') && location.hostname == this.hostname)
或转义字符/
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname)