代码之家  ›  专栏  ›  技术社区  ›  Shakeel Hussain Mir

阻止刷新锚点标记单击

  •  3
  • Shakeel Hussain Mir  · 技术社区  · 7 年前

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

    <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 回复  |  直到 7 年前
        1
  •  2
  •   Mir Shakeel Hussain    7 年前

    $('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;
        });
    
        2
  •  2
  •   Aadil Dedmari    7 年前
    <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>