如何重新启用event.preventDefault? [英] How to reenable event.preventDefault?

查看:155
本文介绍了如何重新启用event.preventDefault?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,我已阻止所有提交按钮的默认操作,但是我想在按钮上重新启用默认提交操作我该怎么办?

I have a web page which I have prevented the default action on all submit buttons, however I would like to re-enable default submit action on a button how can I do this?

我目前正在使用以下方法阻止默认操作:

I am currently preventing the default action using the following:

$("form").bind("submit", function(e){
e.preventDefault();
});

我使用以下方式成功完成了此操作:

I have successfully done this using the following:

$(document).ready(function(){
$("form:not('#press')").bind("submit", function(e){
e.preventDefault();
});

但是我可以在单击按钮时动态执行此操作吗?

But can I do this dynamically when the button is clicked?

推荐答案

您必须取消绑定事件并重新绑定到单独的事件取消绑定后不会阻止默认或仅在方法中调用默认事件。
没有神奇的event.cancelled = false;

You would have to unbind the event and either rebind to a separate event that does not preventDefault or just call the default event yourself later in the method after unbinding. There is no magical event.cancelled=false;

按要求

 $('form').submit( function(ev){

         ev.preventDefault();

         //later you decide you want to submit
         $(this).unbind('submit').submit()

  });

这篇关于如何重新启用event.preventDefault?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆