我如何做一个链接做一些jQuery然后去目的地 [英] How can i make a link do some jquery then go to destination

查看:61
本文介绍了我如何做一个链接做一些jQuery然后去目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有一个链接,在转到目标页面之前,我需要对它进行一些jquery.我确定有很多方法可以做到这一点,最推荐的是什么?

I have a link in a page that I need to do some jquery on before I go to the destination page. Im sure there are dozens of ways to do this, what is most recommended?

$('#link').click(function(){
alert('you clicked'); 
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<a href='google.com' id='link'>Google</a>

显然失败了.有想法吗?

obviously fails. thoughts?

推荐答案

$('#link').click(function(e){
    e.preventDefault();
    alert('you clicked'); 
    window.location.href = $(this).attr('href');
});

在完成您想做的事情之后设置位置.

Set the location after doing whatever you want to do.

这篇关于我如何做一个链接做一些jQuery然后去目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆