jQuery confirm(href)工作不正常

jQuery confirm (href) not working correctly

本文关键字:工作 不正常 href confirm jQuery      更新时间:2023-09-26

我有一个jQuery确认操作没有打开正确的url。它打开表行中的第一个url。

<td><a class="confirm" href="verwijderen.php?page=honden&id=<?php echo $rows['id'];?>" >Verwijder</a></td>

<script>
$(".confirm").confirm({
text: "Weet je het zeker?",
title: "Bevestig verwijderen",
confirm: function(button) {
    window.document.location = $(".confirm").attr("href");
},
cancel: function(button) {
    return false;
},
confirmButton: "Ja, dat weet ik zeker",
cancelButton: "Nee",
post: true
});
</script>

问题是jQuery confirm脚本只执行列表中的第一个url——在本例中为id=1。对于表中的所有其他项,它也执行id=1。当我在表行中搜索url时,它会显示正确的id,比如id=6。脚本执行时出错。

有什么想法吗?

这应该可以解决您的问题:

$(".confirm").each(function(i,confirm) {
    $(confirm).confirm({
        text: "Weet je het zeker?",
        title: "Bevestig verwijderen",
        confirm: function(button) {
            window.document.location = $(confirm).attr("href");
        },
        cancel: function(button) {
            return false;
        },
        confirmButton: "Ja, dat weet ik zeker",
        cancelButton: "Nee",
        post: true
    });
});