【问题标题】:jQuery Clean Confirm Dialog Idea - but onclick does not trigger the new onclick functions when called from eventHandlerjQuery Clean Confirm Dialog Idea - 但从 eventHandler 调用时 onclick 不会触发新的 onclick 函数
【发布时间】: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


    【解决方案1】:

    所以我认为这基本上是先有鸡还是先有蛋的问题。

    在我们捕获事件的那一刻,无法更改事件处理程序,因为它们已经被读取。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 1970-01-01
      • 2012-12-07
      • 1970-01-01
      相关资源
      最近更新 更多