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


当前回答

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

$("#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(); 

});

其他回答

你可以在"preventDefault"方法之后使用这个

/ /这里evt。目标返回默认事件(例如:默认url等)

var defaultEvent=evt.target;

//这里我们保存默认事件..

if("true")
{
//activate default event..
location.href(defaultEvent);
}

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

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

为了执行异步调用,我不得不在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;}

干杯!

我建议采用以下模式:

document.getElementById("foo").onsubmit = function(e) {
    if (document.getElementById("test").value == "test") {
        return true;
    } else {
        e.preventDefault();
    }
}

<form id="foo">
    <input id="test"/>
    <input type="submit"/>
</form>

...除非我遗漏了什么。

http://jsfiddle.net/DdvcX/