index.html:90 Uncaught TypeError: result.test is not a function
在一次运用JavaScript中test()方法时,提示下图所示的错误。

代码如下:
var herf = "www.bookubang.com";
var sea = '/' + key + '=' + value + '&/';
if(sea.test(href)){
console.log(test);
}
之所以如此,是因为正则表达式错误。
解决方法:
var herf = "www.bookubang.com";
var sea = key + '=' + value + '&';
//注意
var sea = new RegExp(sea,'gi');
//new RegExp(sea,'gi')中第二个参数gi分别代表全局匹配和不区分大小写
//或者直接
var sea = new RegExp(key + '=' + value + '&','gi');
if(sea.test(href)){
console.log(test);
}