Javascript-无效量词错误,有人能帮我看看我的错误吗?
我不是JS大师,但有人能帮我找到下面代码段中的无效量词错误吗 提前谢谢! -多原型Javascript-无效量词错误,有人能帮我看看我的错误吗?,javascript,Javascript,我不是JS大师,但有人能帮我找到下面代码段中的无效量词错误吗 提前谢谢! -多原型 function $_GET(q,s) { s = s ? s : window.location.search; var re = new RegExp( '&' + q + '(?:=([^&]*))?(?=&|$)' , 'i' ); return (s=s.replace(/^?/,'&').match(re)) ? (typ
function $_GET(q,s) {
s = s ? s : window.location.search;
var re = new RegExp( '&' + q + '(?:=([^&]*))?(?=&|$)' , 'i' );
return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
?
在正则表达式中有特殊含义,特别是它使前面的项成为可选项。如果您试图查找问号字符本身,则需要使用反斜杠将其转义
function $_GET(q,s) {
s = s ? s : window.location.search;
var re = new RegExp( '&' + q + '(?:=([^&]*))?(?=&|$)' , 'i' );
return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
?
在正则表达式中有特殊含义,特别是它使前面的项成为可选项。如果您试图查找问号字符本身,则需要使用反斜杠将其转义
function $_GET(q,s) {
s = s ? s : window.location.search;
var re = new RegExp( '&' + q + '(?:=([^&]*))?(?=&|$)' , 'i' );
return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined;
}
这应该做什么:
/^?/
?它给了我语法错误:无效的正则表达式:/^?/:无需重复。也许您还可以解释函数应该做什么。您需要转义?或从搜索字符串-s=s | | window.location.search.substring(1)中删除它;该函数应该像var var1=$\u GET('key')一样使用,以便在JavaScription中使用GET var有趣的是,该函数实际上是用于按键标识符使用GET vars的,但我不喜欢在页面上出现错误。这应该做什么:/^?/
?它给了我语法错误:无效的正则表达式:/^?/:无需重复。也许您还可以解释函数应该做什么。您需要转义?或从搜索字符串-s=s | | window.location.search.substring(1)中删除它;该函数应该像var var1=$\u GET('key')一样使用,以便在JavaScription中使用GET var有趣的是,该函数实际上是在按键标识符使用GET vars,但我不喜欢页面上出现错误。