我不是一个JS大师,但有人能帮我找到以下代码片段中的无效量词错误吗?
提前感谢!-mprototype
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;
}