我对这行代码有疑问:
<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>
仍然无法正常工作。
答案 0 :(得分:1)
这样做:
假设您有删除按钮
<button class="delete-it">Delete</delete>
在类delete-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;
});
});
答案 1 :(得分:0)
您可以在confirm
中显示bootbox
对话框,如下所示
bootbox.confirm("Are you sure you want to Delete?", function(result) {
if(result)
window.location = 'delete.php?id=' + id;
});
根据点击result
中的True
或False
,您将Yes
作为No
或Dialog Box
获取。
有关bootbox
确认对话框的详细信息,您可以查看here
答案 2 :(得分:-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>