0
這是我的問題。我想在點擊一個href鏈接時運行一個刪除功能,但我也想要一個確認彈出窗口。目前,刪除腳本正在運行,如果我點擊確定或取消,顯然我只希望它運行,如果我點擊確定。下面是代碼:在同一鏈接中運行2個onclick函數
<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>
我不能相信的解決方案是如此簡單。非常感謝 – user2516546