我正在尝试在我的网站的 javascript 中使用查询字符串,javascript 中是否有一个通配符标记,所以它可能是这样的 * = 通配符
var x = location.search;
if (x=='?test=yes') {
window.location.replace('http://google.com')
}
else {
if (x=='?test=yes&*=123') {
window.location.replace('http://youtube.com')
}
}
这可能吗?
最佳答案
只需使用包含
:
const x = "https://example.com?test=yes&*=123";
console.log(x.includes("?test=yes"));
您也可以使用正则表达式:
const x = "https://example.com?test=yes&*=123";
console.log(/]?test=yes/.test(x));
关于javascript - 如果 location.search == '?test=yes' 之后执行任何其他操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56572582/