读书人

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

发布时间: 2012-05-05 17:21:10 作者: rapoo

怎样在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

读书人网 >JavaScript

热点推荐