js 如果 window.location.href 不匹配,则跳转到
如何进行window.location.href
判断?
如果window.location.href
不匹配?search=
,则使当前url跳转到http://localhost/search?search=car
我的代码不起作用,或者我应该使用 indexOf
来进行判断?谢谢。
if(!window.location.href.match('?search='){
window.location.href = 'http://localhost/search?search=car';
}
How to make a window.location.href
judge?
if window.location.href
not match ?search=
, make the current url jump to http://localhost/search?search=car
my code not work, or I should use indexOf
to make a judge? Thanks.
if(!window.location.href.match('?search='){
window.location.href = 'http://localhost/search?search=car';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几件事:你缺少一个右括号,并且你需要转义 ?因为它对于正则表达式很重要。使用
/\?search=/
或'\\?search='
。或者
A couple of things: you're missing a closing paren, and you need to escape the ? because it's significant to regular expressions. Use either
/\?search=/
or'\\?search='
.or