阻止href在操作后移动到页眉


Preventing href to move to header after action

我有这个代码

<a class ="hi" href='uselesslinkhere.php?page=page1&action=add&id=myid'>Add??</a>

每当有人点击此按钮时,链接就会表现为a href=#。使用jQuery会有帮助吗?如果是,它是如何工作的?

谢谢大家!

在锚标记上添加onclick事件,并在href之后停止页面。然后根据需要通过jQuery更改页面上的内容,并通过历史记录添加所需的url。

<a class ="hi" onclick="loadPage(event,'uselesslinkhere.php?page=page1&action=add&id=myid')" href='uselesslinkhere.php?page=page1&action=add&id=myid'>Add??</a>
var loadPage = function(event,pageUrl){
        event.preventDefault();

        if(history && history.pushState)
            {
                history.pushState(null,null,pageUrl);
            }
       return false;
    }