jQuery

2011-10-06 19 views
9

ile çeşitli seçeneklerle uyarı Alert düğmesine tıkladığınızda silme düğmesine tıkladıktan sonra did you want delete this?'a iki seçenekle sorun olduğunu bildirin: ok ve cancel. Kullanıcı ok'u tıklarsa değer silinir. Kullanıcı cancel numaralı telefonu tıklarsa, değeri silmez. Bu sitedeki Bunun gibijQuery

:

Stackoverflow confirmation dialog for post deletion vote

Nasıl jQuery ile bunu yapmak?

cevap

15
<a href="#" id="delete">Delete</a> 

$('#delete').click(function() { 
    if (confirm('Do you want to delete this item?')) { 
     // do delete item 
    } 
}); 

Kodu: http://jsfiddle.net/hP2Dz/4/

+0

Bu işe yaramadı, bakınız: http://jsfiddle.net/hP2Dz/ –

+0

Evet, '' '' '' '' '' sembolü '' sembolünü unuttum. Şuna bir bakın: http://jsfiddle.net/hP2Dz/4/ – Samich

+0

Uyarı ve değişiklik değeri 'ok' ve 'cancel' için' direction: rtl; ' –

1

jQuery olmasa gerek ama JavaScript'inizde

<html> 
<head> 
<script type="text/javascript"> 
function show_confirm() 
{ 
var r=confirm("vote "); 
if (r==true) 
    { 
    alert("ok delete"); //you can add your jquery here 
    } 
else 
    { 
    alert(" Cancel! dont delete"); //you can add your jquery here 
    } 
} 
</script> 
</head> 
<body> 

<input type="button" onclick="show_confirm()" value="Vote to delete?" /> <!-- can be changed to object binding with jquery--> 

</body> 
</html>Vot 
+1

'var r = onayla ("oy"); if (r == true) '==' (onaylayın ("oy")) –

2

kullanabileceği basit ilkedir, kutunun bu tip confirm değil alert olduğunu. confirm, kullanıcının istemciye olumlu veya olumsuz yanıt verip vermediğini (yani sonucunun true döndürülmesini, cancel tıklatılarak false döndürülmesini) temsil eden bir boole döndürür. Bu jQuery için geçerlidir, ancak JavaScript’te daha geniş kapsamlı olarak da geçerlidir. Şöyle bir şey gibi:

var shouldDelete = confirm("Do you want to delete?"); 
if (shouldDelete) { 
    // the user wants to delete 
} else { 
    // the user does not want to delete 
} 
2

Eğer alert'ünüzü stil bu eklentiyi kontrol etmek istiyorsanız: jquery-alert-dialogs. Kullanımı çok kolay.


UPDATE

jAlert('This is a custom alert box', 'Alert Dialog'); jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) { jAlert('Confirmed: ' + r, 'Confirmation Results'); }); jPrompt('Type something:', 'Prefilled value', 'Prompt Dialog', function(r) { if(r) alert('You entered ' + r); }); 

:
oficial sitesi şu anda çevrimdışı. here is another source

+0

Site şu anda çalışmıyor, ancak şunu buldum: http://labs.abeautifulsite.net/archived/jquery-alerts/demo/ – Kayvar

+0

@Kayvar cevabımı güncelleyecektir. Teşekkürler –