1

所有,我有以下代码:

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>

当我单击按钮时,它只会将我重定向回我所在的页面,而不是转到我指定的取消 url。我提醒 cancel_url,它会告诉我正确的。任何想法我做错了什么?

4

2 回答 2

4

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在 MDN 上查看。

于 2012-07-03T19:15:52.423 回答
0
window.location.href=cancel_url;

应该管用

于 2012-07-03T19:15:53.640 回答