Jquery 启动确认不起作用,因为单击按钮
更新我的ajax删除功能:Jquery 启动确认不起作用,因为单击按钮,jquery,twitter-bootstrap,confirmation,Jquery,Twitter Bootstrap,Confirmation,更新我的ajax删除功能: $('[data-toggle="popover"]').popover({ placement: 'left', html: true, trigger: 'hover' }); $('[data-toggle=confirmation]').confirmation({ btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?' }); 函数删除用户(ele){ 变量id=$(ele.
$('[data-toggle="popover"]').popover({ placement: 'left', html: true, trigger: 'hover' });
$('[data-toggle=confirmation]').confirmation({ btnOkLabel: 'Yes', btnCancelLabel: 'No', title: 'Are you sure?' });
函数删除用户(ele){
变量id=$(ele.attr('data-id');
$.ajax({
键入:“POST”,
cache:false,
url:“../ashx/FriendOperation.ashx”,
数据:{id:id,rol:'',op:},
beforeSend:函数(){
//布拉布拉
},
成功:功能(数据){
var jsonData=JSON.parse(数据);
if(jsonData!=null){
如果(parseInt(jsonData)>0){
警惕(“好的”);
GetFriendOp();
}否则{
警报('expection');
}
}否则{
警报('expection');
}
}
});
}
我可以与AJAX结合使用吗,比如$('#element')。确认('show')代码>
成功:
$(“[data toggle=confirmation]”。确认({btnOkLabel:'Yes',btncancelabel:'No',title:'you sure?',容器:“body”,btnOkClass:'btn btn sm btn success btn xs',btncanceclass:'btn btn sm btn danger btn xs',onConfirm:function(事件,元素){alert('confirm clicked');})
谢谢@DanCouper。内联onclick处理程序将解除任何其他事件处理程序的绑定。您基本上覆盖了bootstrap confirm的功能,在本例中使用confirm也是毫无意义的,因为您只是在编写自己的逻辑。查看Boostrap Confirm文档,它为您提供了添加逻辑的挂钩。不要只是在已经定义了(事件侦听器)行为的东西中添加onclick属性,以及一个允许您执行现在尝试执行的操作的API(如果可能的话,最好不要在HTML中使用onclick属性,但这是另外一回事)hmm您是对的,我覆盖了我可以在ajax上使用的确认,比如$('element).确认(“显示”);合并?在这里的“选项”下:有一个用于onConfirm的选项-因此您可以通过.confirmation({onConfirm(e){…dostuff here}
。基本上应该是这样的-不过可以尝试一下选项-像选项上方的示例那样编写(在$('[data toggle=confirmation]')).确认…
设置呼叫)
<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?' });
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');
}
}
});
}