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

解决方案 »

  1.   

    return false; 不行么?
      

  2.   


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

  3.   

    如果不想用return false;那就这样:<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>
      

  4.   


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

  5.   

    不能在外部写,只能在a里面的onclick事件里禁止
      

  6.   

    onclick="not_jump();return false;"
      

  7.   

    href="javascript:void(0)";或者not_jump()方法后面添加个renturn false