2010-11-24 28 views

Trả lời

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

hay

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

hay thậm chí chỉ cần

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

+1 Bạn là một khẩu súng nhanh hơn tôi :-) –

3

Bạn chỉ có thể trả lại xác nhận ("Bạn có chắc chắn không?"). Điều đó sẽ trả về true hoặc false, trong đó false ngăn chặn hành động.

0
$('a.confirm').click(function(e) { 
    return confirm("Are you sure?") 
}); 
Các vấn đề liên quan