2010-11-24 6 views

risposta

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

o

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

o anche solo

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

+1 Tu sei un pistola più veloce di me :-) –

3

È possibile solo restituire conferma ("Sei sicuro?"). Ciò restituirà vero o falso, laddove falso impedisce l'azione.

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