2012-07-03 82 views
1

所有, 我有下面的代码:jQuery的重定向页面不工作的按钮点击

var site_url = 'http://localhost/website/'; 
jQuery("#cancel_song_choice").click(function(event){ 
    cancel_url = site_url + "event-form"; 
    window.location.href(cancel_url); 
}); 

然后,我有以下的HTML:

<button id="cancel_song_choice">Cancel Search</button> 

当我点击按钮,它只是将我重定向到我所在的页面,而不是转到我指定的取消网址。我提醒了cancel_url,它显示了我正确的一个。任何想法我做错了什么?

+0

使用'了window.location = cancel_url;' –

回答

3

href不是一个函数,它是一个属性。用途:window.location.href = cancel_url;

var site_url = 'http://localhost/website/'; 
jQuery("#cancel_song_choice").click(function(event){ 
    window.location.href = site_url + "event-form"; 
}); 

退房window.location on MDN

+0

感谢那些固定我的问题之一,但由于某种原因,这一次仍然没有回到正确的网址。任何想法为什么它不会这样做? – user1048676

+0

@ user1048676,我不确定你的意思是不会回到正确的URL。你能详细说明一下吗? –

+0

是的,它只是刷新当前页面,而不是将用户重定向到site_url +事件表单url。 – user1048676

0
window.location.href=cancel_url; 

应该工作