如果我单击包含 "href" 的 link,则不会显示 Bootbox 模式

Bootbox modal is not showing up if I click on a link that contains an "href"

好的,所以我使用的 bootbox 工作得很好,但是当我想在 link 和 PHP 中发送变量时,所有 javascript 都可以工作,但 bootbox 不行。

----这个有效----

<a href='#' class="alert_without_href">I dont have an href</a>
<script>
$(document).ready(function()
 {
    $('a.alert_without_href').on('click', function()
    {
        alert('This works');
        bootbox.alert("This ALSO works");
    });
});
</script>

----这不行----

<a href="?name=Jacob" class="alert_with_href">I have an href</a><br><br>
<script>
   $(document).ready(function()
   {
      $('a.alert_with_href').on('click', function()
      {
        alert('This works');
        bootbox.alert("This one DOESNT work"); <---- PROBLEM IS HERE
        alert('This also works');
      });
   });
</script>

----然后最后显示----

<?php
    if ($_SERVER['REQUEST_METHOD'] === 'GET')
    {
        echo 'Hello ' . $_GET["name"];
    }  
?>

我确实需要在link中传递一个变量,它不能被取出来。我该如何解决这个问题?

提前致谢

----编辑---- 我在下面添加了一张 table 的图片,并解释了具体需要做什么

Table of users

--只有在看到图像时才阅读-- 因此 table 中 "Action" 下的每个 link 都会创建一个 link,其中包含用户唯一 ID 的变量。单击它时,我检查是否设置了 $_GET['remove_id'],然后 运行 一个 MySQL 查询以删除具有该 ID 的那个人。

所以基本上 Bootbox 的想法是在你想删除用户时作为确认消息,我不想使用普通的 alert('') 因为它可以被禁用。

p.s。删除功能确实有效,我现在只想使用 bootbox 添加确认。

Bootstrap(因此 Bootbox)模式不会生成阻塞事件,因此如果您希望在单击超链接时发生某些事情,则需要阻止默认行为(页面导航)。类似于:

<a href="?name=Jacob" class="alert_with_href">I have an href</a><br><br>
<script>
   $(document).ready(function() {
      $('a.alert_with_href').on('click', function(e) // <-- add an event variable
      {
        e.preventDefault(); // <-- prevent the event
        bootbox.alert("I am an alert!");
      });
   });
</script>

既然你说要确认某事,请使用 bootbox.confirm 和一些 AJAX:

<a href="?name=Jacob" class="alert_with_href" data-name="Jacob">I have an href</a><br><br>
<script>
    $(document).ready(function() {
        $('a.alert_with_href').on('click', function(e) // <-- add an event variable
        {
            e.preventDefault(); // <-- prevent the event

            var data = { name = $(this).data('name') };
            bootbox.confirm("Really delete?", function(result){
                if(result){
                    $.post('your-url', data)
                        .done(function(response, status, jqxhr){
                            // do something when successful response
                        })
                        .fail(function(jqxhr, status, error){
                            // do something when failure response
                        });
                }// end if
            }); // end confirm
        });
    });
</script>

我还添加了一个数据属性,以便更轻松地获取发布值(不要使用 GET 请求执行删除操作)。我假设您会在成功删除后重新加载页面,或者您可以使用 .remove 删除包含您要删除的项目的 "row"