问题
I have many links in a HTML-table, which delete corresponding row, when clicked (calling a PHP-script via GET parameter).
They all have a class delete_row.
How could I please display a confirm('Really delete?') dialog using jQuery, when such a link is clicked?
And of course prevent following that link when No has been selected in the dialog.
回答1:
Try this.
$('.delete_row').click(function(){
return confirm("Are you sure you want to delete?");
})
回答2:
Very simple and effective one line solution without using jquery:
<a href="to/your/path" onclick="return confirm('Are you sure you want to delete?');">Delete</a>
回答3:
you can use preventDefault method of the event object in the handler function:
jQuery('.delete_row').click(function(event){
if(!confirm('Really Delete?')){
event.preventDefault();
}
})
回答4:
You could also call another function after confirm like this:
<a href="to/your/path" onclick="return confirm('Are you sure you want to delete?') && yourOtherFunction();">Delete</a>
回答5:
I think there is a error!
Use this:
$('.delete_row').click(function(){
return confirm("Are you sure you want to delete?");
});
来源:https://stackoverflow.com/questions/9044806/how-to-confirm-clicking-on-a-link-using-jquery