2015-09-07 66 views
-1

我有兩個按鈕:刪除和更新。這些按鈕被點擊時加載到http://homepage/?removed_item=1http://homepage/cartjquery重定向到另一個鏈接時,點擊一個按鈕

所以我想要的只是重定向到主頁。 這是可能使用jQuery ..

他們班是:卸下襬臂和.update

編輯:按鈕被點擊並做它的進程後,它會重定向

+1

你的意思是在按鈕被點擊並完成它的過程之後,它會重定向。或者你只是想讓他們直接進入主頁嗎? – Stewartside

+0

http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-using-jquery?rq=1 –

+0

@Stewartside是的,謝謝你..按鈕被點擊後已經完成了它的過程,它會重定向,我編輯我的原始帖子。 –

回答

0

你可以做類似的東西:

$(".remove").click(function() { 
    window.location = "http://homepage/"; 
}); 

$(".update").click(function() { 
    window.location = "http://homepage/"; 
}); 
0

修訂

event.preventDefault():如果調用此方法,則不會觸發該事件的默認操作。

你應該使用JQuery方法event.preventDefault()防止默認href,然後重定向到主頁。

HTML:

<a href='http://homepage/cart' class='update'>Update</a> 
<a href='http://homepage/?removed_item=1' class='remove'>Remove</a> 

JS:

$(".update, .remove").click(function(e) { 
    e.preventDefault(); 
    window.location.replace("http://homepage/"); 
}); 

如果你想整理工藝後重定向,您必須使用jQuery函數$.get()

JS:

$(".update, .remove").click(function(e) { 
    e.preventDefault(); 

    $.get($(this).attr('href'),function(result){ 
     window.location.replace("http://homepage/");   
    }) 
}); 

希望這有助於。

+0

event.preventDefault(進程代碼)不是一個jQuery方法 –

+0

[jQuery的event.preventDefault()方法(http://www.w3schools.com/的jquery/event_preventdefault.asp)。 –

+0

https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault 要清楚:它也是「jquery event arg」的一種方法! –

相關問題