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


当前回答

function(evt) {evt.preventDefault();}

它的反面

function(evt) {return true;}

干杯!

其他回答

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

干杯!

你可以在你的脚本中使用这个附加到一些点击事件:

location.href = this.href;

用法示例如下:

jQuery('a').click(function(e) {
    location.href = this.href;
});

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

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

我建议采用以下模式:

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/