单击按钮时jquery重定向到另一个链接
我有两个按钮:删除和更新。单击这些按钮时,将其加载到或 所以我只想重定向到主页。 用jquery可以吗 它们的类是:。删除和。更新单击按钮时jquery重定向到另一个链接,jquery,redirect,hyperlink,Jquery,Redirect,Hyperlink,我有两个按钮:删除和更新。单击这些按钮时,将其加载到或 所以我只想重定向到主页。 用jquery可以吗 它们的类是:。删除和。更新 编辑:单击按钮并完成其过程后,它将重定向您可以执行以下操作: $(".remove").click(function() { window.location = "http://homepage/"; }); $(".update").click(function() { window.location = "http://homepage/"; });
编辑:单击按钮并完成其过程后,它将重定向您可以执行以下操作:
$(".remove").click(function() {
window.location = "http://homepage/";
});
$(".update").click(function() {
window.location = "http://homepage/";
});
已更新 event.preventDefault():如果调用此方法,则不会触发事件的默认操作 您应该使用JQuery方法来阻止默认的
href
,然后重定向到主页
HTML:
<a href='http://homepage/cart' class='update'>Update</a>
<a href='http://homepage/?removed_item=1' class='remove'>Remove</a>
$(".update, .remove").click(function(e) {
e.preventDefault();
window.location.replace("http://homepage/");
});
$(".update, .remove").click(function(e) {
e.preventDefault();
$.get($(this).attr('href'),function(result){
window.location.replace("http://homepage/");
})
});
如果要在完成过程后重定向,必须使用JQuery函数
JS:
<a href='http://homepage/cart' class='update'>Update</a>
<a href='http://homepage/?removed_item=1' class='remove'>Remove</a>
$(".update, .remove").click(function(e) {
e.preventDefault();
window.location.replace("http://homepage/");
});
$(".update, .remove").click(function(e) {
e.preventDefault();
$.get($(this).attr('href'),function(result){
window.location.replace("http://homepage/");
})
});
希望这有帮助。您的意思是,在单击按钮并完成其过程后,它将重定向。还是你想让他们直接进入主页?@Stewartside是的,谢谢。。单击按钮并完成其过程后,它将重定向,我编辑我的原始帖子。然后,这将在实际页面本身上完成,而不是在单击事件上完成。您需要为它在两个pagesevent上运行的进程提供代码。preventDefault()不是jQuery方法。需要说明的是:它也是“jquery事件arg”的一种方法!我试过了,但它没有先执行删除和更新以及重定向。还有别的办法吗?我也编辑了我原来的帖子,来解释更多!在评论中总结事件讨论。“jQuery的事件系统根据W3C标准规范化事件对象。事件对象保证传递给事件处理程序。原始事件的大多数属性被复制并规范化为新事件对象。”