js阻止a标签默认跳转

函数:

    // 阻止默认跳转
    function stopDefault( e ) { 
         if ( e && e.preventDefault ) 
            e.preventDefault(); 
        else 
            window.event.returnValue = false; 
        return false; 
    } 

使用示例:

    // 阻止所有a标签的跳转
    $(document).ready(function(){
        $(document).on('click','a',function(e){
            stopDefault(e);
        });
    });

猜你喜欢

转载自www.cnblogs.com/mankii/p/10076311.html
今日推荐