【问题标题】:can e.preventDefault() be reversed?e.preventDefault() 可以反转吗?
【发布时间】:2012-03-04 15:26:43
【问题描述】:

我正在寻找一种方法来 .preventDefault() 进行转换,然后允许默认行为

$('.withTrans').click(function(e){
    e.preventDeault();
    $(this).animate('opacity','0',300,function(){
           e.resumeDefault();      // does something like this exist?
    });

})

【问题讨论】:

标签: javascript jquery events preventdefault


【解决方案1】:
$('.withTrans').click(function(event) {
    if ( $(this).data("prevented") === true ) {
        $(this).data("prevented", false);
        return;
    }
    event.preventDefault();
    $(this).animate('opacity', '0', 300, function() {
           $(this).data("prevented", true).trigger("click");
    });
});

【讨论】:

  • 这不是触发 ...trigger("click") 来重新触发相同的点击事件。有什么建议吗?
【解决方案2】:

假设您在动画完成后尝试点击链接:

$('.withTrans').click(function(e){
    $(this).animate('opacity','0',300,function(){
          window.location= this.href;
    });
    return false;
});

【讨论】:

    【解决方案3】:
    $('.withTrans').each(function(e){
        $(this).unbind();
    }
    

    【讨论】:

    • 请描述一下,这个答案是如何解决问题的
    猜你喜欢
    • 2014-04-29
    • 1970-01-01
    • 2011-05-31
    • 2019-07-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多