【发布时间】:2012-01-06 12:10:22
【问题描述】:
因此,由于 jQuery 确认框看起来很棒,我认为我们需要使它真正有用,使其能够与所有其他点击事件和内联处理程序一起使用,而无需麻烦和丑陋的 hack,例如重定向浏览器 url。
所以我想出了这个编辑新版本 jQuery confirm dialog idea to capture click events before onclick can get triggered
我认为在访问该对象的 eventHandler 时,更新内联处理程序已经太晚了。 或者有什么办法?
代码:
$(function(){
$(".needsFancyConfirm").each(function(index, ele){
ele=$(ele);
ele._onclick=ele.attr("onclick");
ele.attr("onclick", "return false;"); //preventDefault would do the same imho
ele.bind("click.foo",function(){
$("#dialog").dialog({
bgiframe: true,
height: 300,
modal: true,
buttons: {
SubmitFormWithAllOldOnclickEvents: function() {
$(this).dialog('close');
ele.attr("onclick",ele._onclick);
ele.unbind("click", "click.foo");
console.info(ele.attr('onclick') + " <-- just to make sure what is written in Onclick, now we will execute it");
console.info($("#coolIdea")[0].onclick() + " <-- this returns false - it should return the set old onclick e.g. alert Wow u managed to execute me");
}
}
});
});
});
});
【问题讨论】:
标签: jquery dialog jquery-events confirm