防止刷新锚点标记点击

问题描述:

我想要使用锚点标记来加载页面,就像这样从任何内容页面转到。我想阻止页面刷新锚点标记单击但同时它应该加载不同的页面。下面的例子这里是内容页防止刷新锚点标记点击

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
    <a href="WebForm2.aspx">go</a> 
</asp:Content> 

和母版页

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
     <ContentTemplate> 
      <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> 
      </asp:ContentPlaceHolder> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
+2

使用'LinkBut​​ton'并加载内容页面并点击它 – Imad

+1

什么都没有发生@Imad –

下面将不会在服务器端控制工作,还需要更改所有内容页到个人。

$('a').click(function (e) { 
     var page = $(this).attr('href'); 
     if (page!='#') { 
      window.history.pushState("string", "Title", page); 
      $("#divid").load(page, function() { 
       //write your stuff 
      }); 
     } 
     e.preventDefault(); 
     e.stopPropagation(); 
     return false; 
    }); 

<a class="link1" href="WebForm2.aspx">go</a> 


<script> 
$(function(){ 
    $("a.link1").click(function() 
    { 
     $.get("WebForm2.aspx"); 
     return false; // prevent default browser refresh on "#" link 
    }); 
}); 
</script>