2010-11-24 15 views

Odpowiedz

12
$('a.confirm').click(function(e) { 
    var answer = confirm("Are you sure?") 
    if (answer){ 
     // do the default action 
    } else { 
     e.preventDefault(); 
    } 
}); 

lub

$('a.confirm').click(function(e) { 
    var answer = confirm("Are you sure?") 
    if (!answer){ 
     e.preventDefault(); 
    } 
}); 

lub nawet tylko

$('a.confirm').click(function(e) { 
    return confirm("Are you sure?"); 
}); 
+0

+1 Jesteś szybszy niż pistolet mnie :-) –

3

Możesz po prostu wrócić potwierdzić ("Jesteś pewien?"). To zwróci true lub false, gdzie false uniemożliwia działanie.

0
$('a.confirm').click(function(e) { 
    return confirm("Are you sure?") 
}); 
Powiązane problemy