javascript - event.preventDefault() vs. return false

Mots clés : javascriptjqueryevent-handlingdom-eventsevent-propagationjavascript

meilleur 1 Réponses javascript - event.preventDefault() vs. return false

vote vote

92

$('a').click(function (e) {   // custom handling here    // oops...runtime error...where oh where will the href take me?    return false; }); 
$('a').click(function (e) {   e.preventDefault();    // custom handling here    // oops...runtime error, but at least the user isn't navigated away. }); 

Questions similaires