我在一个HTML表格中有许多链接,当点击时会删除对应的行(通过GET参数调用PHP脚本)。
它们都有一个名为 delete_row 的class。
当点击这样的链接时,我该如何使用jQuery显示一个 confirm('真的要删除吗?') 对话框?
当在对话框中选择 No 时,当然要防止跟随该链接。
试试这个。
$('.delete_row').click(function(){
return confirm("Are you sure you want to delete?");
})
非常简单且有效的一行解决方案,无需使用 jQuery:
<a href="to/your/path" onclick="return confirm('Are you sure you want to delete?');">Delete</a>
jQuery('.delete_row').click(function(event){
if(!confirm('Really Delete?')){
event.preventDefault();
}
})
我认为有一个错误!
使用这个:
$('.delete_row').click(function(){
return confirm("Are you sure you want to delete?");
});
<a href="to/your/path" onclick="return confirm('Are you sure you want to delete?') && yourOtherFunction();">Delete</a>