-1

我对这行代码有疑问:

<script type='text/javascript'>
function delete_user( id ){

    var answer = confirm('Are you sure?');

    //if user clicked ok
    if ( answer ){
        //redirect to url with action as delete and id to the record to be deleted
        window.location = 'delete.php?id=' + id;
    }
}
</script>

如何在此处应用 bootbox.js。我讨厌旧的 javascript 对话框。我怎样才能改变这个?

我已经做了这条线:

<script src="bootstrap.min.js"></script>

还是行不通。

4

3 回答 3

1

只需这样做:

假设您有删除按钮

<button class="delete-it">Delete</delete>

在类的点击事件下写 thisdelete-it

 $(".delete-it").click(function(){
    bootbox.confirm("Are you sure?", function(result) {
      if(result)
          window.location = 'delete.php?id=' + id;
    }); 
  });

根据以下评论:

使用onclick被认为是不好的做法。如果你有$id像这样的数据属性包装它的价值

<a href='#' data-id=' {$id }' class='delete-it'>Delete</a>

并将 JS 更改为:

 $(".delete-it").click(function(){
    var id = $(this).data('id');
    bootbox.confirm("Are you sure?", function(result) {
      if(result)
          window.location = 'delete.php?id=' + id;
    }); 
  });
于 2014-08-24T07:08:08.957 回答
0

您可以显示如下confirm对话框bootbox

bootbox.confirm("Are you sure you want to Delete?", function(result) {
  if(result)
      window.location = 'delete.php?id=' + id;
});

您将获得resultasTrueFalse取决于单击YesNo中的Dialog Box

有关bootbox确认对话框的更多信息,您可以查看此处

于 2014-08-24T07:07:01.157 回答
-1

试试这个:

<!-- JS dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="bootstrap.min.js"></script>

<!-- bootbox code -->
<script src="bootbox.min.js"></script>

<script type='text/javascript'>

function delete_user( id )
{
    bootbox.confirm("Are you sure?", function(result) 
    {
        answer = result;
    }); 

    //if user clicked ok
    if ( answer ){
        //redirect to url with action as delete and id to the record to be deleted
        window.location = 'delete.php?id=' + id;
    }
}
</script>
于 2014-08-24T07:09:05.880 回答