一旦我触发了event . preventdefault(),我如何再次恢复默认操作?
当前回答
你可以在你的脚本中使用这个附加到一些点击事件:
location.href = this.href;
用法示例如下:
jQuery('a').click(function(e) {
location.href = this.href;
});
其他回答
我建议采用以下模式:
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/
好的!它适用于点击事件:
$("#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();
});
event.preventDefault(); //or event.returnValue = false;
及其反义词(标准):
event.returnValue = true;
来源: https://developer.mozilla.org/en-US/docs/Web/API/Event/returnValue
function(evt) {evt.preventDefault();}
它的反面
function(evt) {return true;}
干杯!
你可以在"preventDefault"方法之后使用这个
/ /这里evt。目标返回默认事件(例如:默认url等)
var defaultEvent=evt.target;
//这里我们保存默认事件..
if("true")
{
//activate default event..
location.href(defaultEvent);
}