function完成后获取事件
我有一个人们可以删除记录的表格;
Delete Record 1 Delete Record 2 Delete Record 3
为了确保他们确定,我正在使用“你确定”的确认脚本( Popconfirm ),它提供了一个很好的小弹出确认。
$(".confirm-action").popConfirm();
如果用户单击取消,则不会发生任何操作 如果他们单击“是” – 则处理链接并删除记录。 这是按预期工作的。
现在不是跟随链接(当用户点击’是’时),我想发出一个ajax请求:
$('.confirm-action').click(function(event) { event.preventDefault(); $.ajax({ // Ajax stuff here }); }); $(".confirm-action").popConfirm();
问题是当我尝试这个时,函数在预期时以正确的顺序触发,除了event
为null
,因此脚本失败。
当event
为null
,如何“ preventDefault()
”和/或手动获取event
以防止浏览器跟踪链接?
编辑: JSFiddle显示问题。
正如评论中所指出的,该插件非常糟糕,并且与_data(events)
播放IE播放jQuery的内部事件管理。
如果您不关心UI,我建议您使用SO中使用的正常confirm()
。
我在输入这个答案时为你创建了这个:
$.fn.nativeConfirm = function (options) { return this.click(function () { var bool = confirm(options.text); bool ? options.yes.call(this) : options.no.call(this); }); }
例:
$('a').nativeConfirm({ yes: function(){ alert('yes'); }, no:function(){ alert('no'); }, text: 'Seriously?' });