这是我的问题。我想在单击 href 链接时运行删除功能,但我也希望有一个确认弹出窗口。目前,如果我单击“确定”或“取消”,删除脚本正在运行,所以显然我只希望它在单击“确定”时运行。这是代码:
<a class=\"deletelink delete$postid\" href=\"#\" data-post=\"$postid\" data-type=\"$posttype\" data-file=\"$postmedia\" onclick=\"return deletepost();\">Delete</a>
<script type="text/javascript">
function deletepost(){
var deletequestion = confirm("You are about to delete one of your posts");
if(deletequestion){
return true;
}else{
return false;
}
}
</script>
<script type="text/javascript">
$('.deletelink').on('click', function()
{
var post = $(this).attr("data-post");
var file = $(this).attr("data-file");
var type = $(this).attr("data-type");
jQuery.post("php/delete.php", {
post:post,
file:file,
type:type
}, function(data, textStatus){
if(data == 1){
$('.delete' + post).html("Deleted").addClass("disableClick");
}else{
$('.delete' + post).html("Error");
}
});
return false;
});
</script>