防止锚标记点击刷新

Prevent Refresh on anchor tag Click

我想使用这样的锚标记从任何内容页面加载页面。我想阻止锚标记点击页面刷新,但同时它应该加载不同的页面。下面的示例是内容页面

<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>
<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>

以下内容不适用于服务器端控件,您还需要将所有内容页面更改为单独的。

$('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;
    });