2016-08-30 209 views

回答

1
echo "<td><a onClick=\"javascript: return confirm('Please confirm deletion');\" href='delete.php?id=".$query2['id']."'>x</a></td><tr>"; //use double quotes for js inside php! 
1
$('#btnDelete').click(function(){ 
    //Clicking on Yes returns true, No returns false; 
    return confirm('Do you want to Delete ?'); 
}); 
2

關注這個example jQuery的刪除確認消息。

HTML

<a class="removeRecord" href="#">Delete</a> 

JS

$("a.removeRecord").live("click",function(event){ 
    event.stopPropagation(); 
    if(confirm("Do you want to delete?")) { 
    this.click; 
     alert("Ok"); 
    } 
    else 
    { 
     alert("Cancel"); 
    }  
    event.preventDefault(); 

}); 
+0

'.live'已被棄用(http://api.jquery.com/live/),因爲jquery1.7並已從jquery1.9中刪除。最好使用'.on'。 Downvoted。 – Samundra

+0

是的,你是對的:) –

1

您可以使用SweetAlert。它是彈出式的jQuery插件。對於刪除彈出窗口,SweetAlert提供以下代碼片段。

swal({ 
    title: "Are you sure?", 
    text: "You will not be able to recover this imaginary file!", 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Yes, delete it!", 
    closeOnConfirm: false 
}, 
function(){ 
    swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
}); 

按照SweetAlert文檔進行集成到您的項目。 讓我們知道你是否有任何困難來整合它。

0

您可以在單行代碼中執行此操作;

<a onclick="return confirm('Sure?');" href="http://example.com/delete">Delete</a>