日期:2014-05-16  浏览次数:20498 次

js如何为链接绑定点击事件并且附带return false;来阻止跳转
<a href="demo" onclick="return hello();" >点击</a>
hello()返回false即可阻止链接跳转。
但我用chrome看g+页面上的a标签并没有onclick属性,那么是怎么做的?点击链接,阻止跳转,用ajax来加载内容。

另外问一下,有没有什么技术让网页地址栏变化但内容看起来没有另外加载过? 例如github

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>
        <style>
        
        </style>
    </head>
    <body>
        <a href="http://www.baidu.com" target="_blank">百度跳转</a>
        <a href="http://www.baidu.com" target="_blank" id="test">阻止默认事件</a>
        <script>
            document.getElementById('test').onclick = function(e){
                e = e || window.event;
                if (e.preventDefault) {
                    e.preventDefault();
                } else {
                    e.returnValue = false;
                }
            }
        </script>
    </body>
</html>

------解决方案--------------------
楼主 搜下 history.pushState

没实验过。。。