Bootstrap 由于点击按钮,确认无效
Bootstrap Confirmation doesnt work because of button onclick
<script src="path/to/jquery.js"></script>
<script src="path/to/bootstrap.js"></script>
<script src="path/to/bootstrap-confirmation.js"></script>
我用Bootstrap确认。
这行不通:
<a class="btn btn-danger btn-xs" data-toggle="confirmation"
onclick="DeleteUser(this);" data-id="10"><span class="fa fa-plus">
</span> Delete</a>
这适用于同一页:
<button class="btn btn-default" data-
toggle="confirmation">Confirmation</button>
<a class="btn btn-default" data-toggle="confirmation">Confirmation1</a>
我的文档准备确认设置
$('[data-toggle="popover"]').popover({ placement: 'left', html: true, trigger: 'hover' });
$('[data-toggle=confirmation]').confirmation({ btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?' });
更新 我的 ajax 删除功能:
function DeleteUser(ele) {
var id = $(ele).attr('data-id');
$.ajax({
type: 'POST',
cache: false,
url: '../ashx/FriendOperation.ashx',
data: { id: id, rol: ' ' ,op:<%=(int)CrudOp.Delete%>},
beforeSend: function () {
//bla bla
},
success: function (data) {
var jsonData = JSON.parse(data);
if (jsonData != null) {
if (parseInt(jsonData) > 0) {
alert('okey');
GetFriendOp();
} else {
alert('expception');
}
} else {
alert('expception');
}
}
});
}
我可以像$('#element').confirmation('show');
那样与AJAX结合使用吗
成功 :
$("[data-toggle=confirmation]").confirmation({btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?',container:"body",btnOkClass:"btn btn-sm btn-success btn-xs",btnCancelClass:"btn btn-sm btn-danger btn-xs",onConfirm:function(event, element) { alert('confirm clicked'); }});
感谢@DanCouper。
内联 onclick 处理程序将取消绑定任何其他事件处理程序。您基本上是在覆盖 bootstrap confirm 所做的 ,在这种情况下您甚至使用 confirm 是完全没有意义的,因为您只是在编写自己的逻辑。查看 Boostrap Confirm 文档,它为您提供了用于添加逻辑的挂钩。不要只是将 onclick 属性添加到已经定义(事件侦听器)行为的东西和 API 允许你做你现在想做的事情(理想情况下根本不要使用 onclick 属性 HTML 如果可能,但那是另外一回事)
<script src="path/to/jquery.js"></script>
<script src="path/to/bootstrap.js"></script>
<script src="path/to/bootstrap-confirmation.js"></script>
我用Bootstrap确认。
这行不通:
<a class="btn btn-danger btn-xs" data-toggle="confirmation"
onclick="DeleteUser(this);" data-id="10"><span class="fa fa-plus">
</span> Delete</a>
这适用于同一页:
<button class="btn btn-default" data-
toggle="confirmation">Confirmation</button>
<a class="btn btn-default" data-toggle="confirmation">Confirmation1</a>
我的文档准备确认设置
$('[data-toggle="popover"]').popover({ placement: 'left', html: true, trigger: 'hover' });
$('[data-toggle=confirmation]').confirmation({ btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?' });
更新 我的 ajax 删除功能:
function DeleteUser(ele) {
var id = $(ele).attr('data-id');
$.ajax({
type: 'POST',
cache: false,
url: '../ashx/FriendOperation.ashx',
data: { id: id, rol: ' ' ,op:<%=(int)CrudOp.Delete%>},
beforeSend: function () {
//bla bla
},
success: function (data) {
var jsonData = JSON.parse(data);
if (jsonData != null) {
if (parseInt(jsonData) > 0) {
alert('okey');
GetFriendOp();
} else {
alert('expception');
}
} else {
alert('expception');
}
}
});
}
我可以像$('#element').confirmation('show');
成功 :
$("[data-toggle=confirmation]").confirmation({btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?',container:"body",btnOkClass:"btn btn-sm btn-success btn-xs",btnCancelClass:"btn btn-sm btn-danger btn-xs",onConfirm:function(event, element) { alert('confirm clicked'); }});
感谢@DanCouper。
内联 onclick 处理程序将取消绑定任何其他事件处理程序。您基本上是在覆盖 bootstrap confirm 所做的 ,在这种情况下您甚至使用 confirm 是完全没有意义的,因为您只是在编写自己的逻辑。查看 Boostrap Confirm 文档,它为您提供了用于添加逻辑的挂钩。不要只是将 onclick 属性添加到已经定义(事件侦听器)行为的东西和 API 允许你做你现在想做的事情(理想情况下根本不要使用 onclick 属性 HTML 如果可能,但那是另外一回事)