我有两个链接,它们在主页上向用户隐藏不同的信息。如果单击其中一个链接,则新信息将显示在屏幕上。问题是,当我单击任何一个链接时,窗口会回到页面顶部。我希望防止这种行为,因为它很烦人。
以下是链接的代码:
以下是链接的代码:
<div align="right" id="ajaxIncomingMail"><a href="#" class="incomingMail">Incoming Mail</a></div><div id="ajaxOutgoingMail"><h5><a href="#" class="outgoingMail">Outgoing Mail</a></h5></div>
这里是jQuery的代码:
$(function(){
$("a.incomingMail").click(function(e){
e.preventDefault();
$("#ajaxMailShowContentOutbox").hide();
$("#ajaxMailShowContentInbox").fadeIn("slow");
});
$("a.outgoingMail").click(function(e){
e.preventDefault();
$("#ajaxMailShowContentInbox").hide();
$("#ajaxMailShowContentOutbox").fadeIn("slow");
});
return false;
});
我在这里使用preventDefault(),但它仍然不起作用!?我还尝试了return false,但也没有起作用。我不知道是否重要,但展示的信息是通过php从数据库中提取的。当我点击链接时,如何停止滚动?