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

怎样在onclick的函数里面禁止a跳转?
怎样在onclick的函数里面禁止a跳转?


------解决方案--------------------
如果不想用return false;那就这样:
HTML code

<a id="a" href="http://www.sohu.com">aa</a>
<script type="text/javascript">
    var el = document.getElementById('a');
    el.onclick = function(e){
        alert('1');
        e = e || window.event;
        if(e.preventDefault){ // w3c
            e.preventDefault();
        } else { // ie
            e.returnValue = false;
        }
    }
</script>

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

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>    
        <style>
        </style>        
    </head>
    <body>
        <a href="http://baidu.com" id="test">123</a>
        <script>
            function $(el){
                return typeof el == 'string' ? document.getElementById(el) : el;
            }
            $('test').onclick = function(){
                this.href = 'javascript://';
            }
        </script>
    </body>
</html>

------解决方案--------------------
onclick="not_jump();return false;"
------解决方案--------------------
href="javascript:void(0)";或者not_jump()方法后面添加个renturn false