[英]Why isn't this javascript redirecting?
I want to have the user click on a button and redirect him/her to a different site I have used the window.location before but for some reason it's not working this time.我想让用户单击一个按钮并将他/她重定向到另一个站点,我以前使用过 window.location 但由于某种原因这次它不起作用。 I'm sure the selector is correct as if I change
window.location
to alert
it alerts every time, so I can't figure what I'm doing wrong.我确定选择器是正确的,就像我更改
window.location
以alert
它每次都发出警报一样,所以我不知道我做错了什么。
$('#show').click(function(){
if($('select[name="customers"]').val() == '')
window.location.replace = 'http://google.com/';
});
You have to use either你必须使用
window.location.replace("http://google.com"); // This is like http redirect
or或者
window.location.href = "http://google.com"; // This is like a link
You can't do window.location.replace= "http://google.com";
你不能做
window.location.replace= "http://google.com";
its a method, not a property.它是一种方法,而不是属性。
window.location.replace('http://google.com/');
Shouldn't that be windows.location.href =...
?那不应该是
windows.location.href =...
吗?
Set just window.location.href
.只设置
window.location.href
。 Like this:像这样:
window.location.href = 'http://google.com/';
try: window.location = 'http://google.com'
尝试:
window.location = 'http://google.com'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.