一旦我触发了event . preventdefault(),我如何再次恢复默认操作?


当前回答

为了执行异步调用,我不得不在jQuery中延迟表单提交。下面是简化的代码…

$("$theform").submit(function(e) {
    e.preventDefault();
    var $this = $(this);
    $.ajax('/path/to/script.php',
        {
        type: "POST",
        data: { value: $("#input_control").val() }
    }).done(function(response) {
        $this.unbind('submit').submit();
    });
});

其他回答

为了执行异步调用,我不得不在jQuery中延迟表单提交。下面是简化的代码…

$("$theform").submit(function(e) {
    e.preventDefault();
    var $this = $(this);
    $.ajax('/path/to/script.php',
        {
        type: "POST",
        data: { value: $("#input_control").val() }
    }).done(function(response) {
        $this.unbind('submit').submit();
    });
});
function(evt) {evt.preventDefault();}

它的反面

function(evt) {return true;}

干杯!

event.preventDefault(); //or event.returnValue = false;

及其反义词(标准):

event.returnValue = true;

来源: https://developer.mozilla.org/en-US/docs/Web/API/Event/returnValue

我使用了以下代码。这对我来说很有效。

$('a').bind('click', function(e) {
  e.stopPropagation();
});

好的!它适用于点击事件:

$("#submit").click(function(event){ 
  
   event.preventDefault();

  // -> block the click of the sumbit ... do what you want

  // the html click submit work now !
  $("#submit").unbind('click').click(); 

});