Javascript 抑制锚定标记<;a>;使用jquery时href

Javascript 抑制锚定标记<;a>;使用jquery时href,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有以下代码: <script type="text/javascript"> $(document).ready(function() { $("#thang").load("http://www.yahoo.com"); $(".SmoothLink").click( function() { $("#thang").fadeOut(); $("#thang").load($(this).attr("href")

我有以下代码:

  <script type="text/javascript">

  $(document).ready(function() 
  {
    $("#thang").load("http://www.yahoo.com");

    $(".SmoothLink").click( function()
    {
      $("#thang").fadeOut();

      $("#thang").load($(this).attr("href"));           

      $("#thang").fadeIn();

    });
  });

  </script>

  <a href="http://www.google.com" id="thelink" class="SmoothLink">click here</a><br /><br />
  <div style="border: 1px solid blue;" id="thang">
  </div>

$(文档).ready(函数()
{
$(“#thang”)。加载(“http://www.yahoo.com");
$(“.SmoothLink”)。单击(函数()
{
$(“#thang”).fadeOut();
$(“#thang”).load($(this.attr(“href”));
$(“#thang”).fadeIn();
});
});


我试图实现的是通过简单地在某些链接上放置一个类(我想加载到div中)来快速、简单地ajax通知网站。我遇到的问题是,正常的锚定操作正在被触发,只是正常地重定向到链接href。如何抑制正常的锚定动作?

通常:

$('a').click(function(e) {
    //prevent the 'following' behaviour of hyperlinks by preventing the default action
    e.preventDefault();

    //do stuff

});
或:

更多信息:

关于
返回false
e.preventDefault()之间区别的上一个问题


与您的问题并不完全相关,但与其这样做,不如

$("#thang").fadeOut();
$("#thang").load($(this).attr("href"));
$("#thang").fadeIn();
…jQuery旨在让您链接方法,例如:

$("#thang").fadeOut().load($(this).attr("href")).fadeIn();

你不需要传递e吗?你需要在你的第一个函数定义中添加
e
参数,但除此之外,光速和+1。对于第一个,不应该有一个var传递到名为“e”的函数中吗?不管怎样,习惯性地传递e也不会有什么坏处。
$("#thang").fadeOut().load($(this).attr("href")).fadeIn();