Maison  >  Questions et réponses  >  le corps du texte

javascript - a标签的取消默认行为

<a href="http://www.baidu.com/" onclick="func()" target="_blank">123</a>

function func(){
    alert(123);
    return false;
}
上述代码仍然跳转到百度。为什么
<a href="http://www.baidu.com/" onclick="func();return false;" target="_blank">123</a>
就可以取消跳转的默认行为。写在函数里就不行?
PHPzPHPz2750 Il y a quelques jours1127

répondre à tous(11)je répondrai

  • 迷茫

    迷茫2017-04-10 15:37:03

    <a href="javascript:;" onclick="func()" target="_blank">123</a>
    <a href="javascript:void();" onclick="func()" target="_blank">123</a>
    

    répondre
    0
  • Annulerrépondre