我不得不问你是否真的要删除所选项目,我想使用bootbox ....这不起作用!
<s:a onclick="return bootbox.confirm('Are you sure?')" action="deleteElement">
答案 0 :(得分:5)
对于投票决定关闭此 的人,我不明白对此有何不清楚,因为问题非常明确,OP是没有使用正确的语法。期待
bootbox.confirm()
或其他什么,需要回调函数,这不会以传统方式工作。
您必须使用callback
function:
$(function () {
$("a").click(function (e) {
e.preventDefault();
bootbox.confirm('Do you really wanna delete?', function (res) {
if (res)
location.href = 'http://www.example.com/';
});
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<a href="http://www.example.com/" action="deleteElement" class="btn btn-danger">Delete</a>
答案 1 :(得分:1)
$(function () {
$(".confirm").click(function (e) {
e.preventDefault();
bootbox.confirm({
message: "This is a confirm with custom button text and color! Do you like it?",
buttons: {
confirm: {
label: 'yes',
className: 'btn-success'
},
cancel: {
label: 'no',
className: 'btn-danger'
}
},
callback: function (result) {
if (result)
console.log('yes');
}
});
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
<a href="http://www.example.com/" action="deleteElement" class="btn btn-danger confirm">Delete</a>