简体   繁体   English

如何停止preventDefault()函数的工作

[英]How to stop the working of preventDefault() function

How to stop the preventDefault() function and what is opposite function of the preventDefault() function. 如何停止preventDefault()函数,什么是相反功能preventDefault()函数。 How to enable the links after call of ajax stop function? 调用ajax stop函数后如何启用链接?

Simple don't use it! 简单不要使用它!

If your link is : 如果您的链接是:

<a href="www.google.com" id="myLink">link</a>

and your event is: 您的事件是:

$('#myLink').click(function(){
console.log('no prevent')
//some code
return true:
});

after log you go to google... 登录后,您转到Google ...

You are using preventDefault() as 您正在使用preventDefault()作为

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

and its opposite 与之相反

function(e){ return true; }

Hope it will help you :) 希望它能对您有所帮助:)

Reference 参考

There isn't an opposite to preventDefault() . preventDefault()没有相反的preventDefault() The opposite to that would be 'do default' which, of course, is done, by default. 与之相反的是“默认情况下”,这当然是默认完成的。 You need to run a condition that will decide whether the default is prevented, before preventing it. 您需要运行一个条件,该条件将决定是否阻止默认设置,然后再阻止它。

//Your hypothetical 'do default'
e.preventDefault()
if(condition){
    e.doDefault(); //METHOD DOES NOT EXIST!
}

//How you should do it
if(!condition){
    e.preventDefault();
}
return false; e.preventDefault(); 

both work same it prevents the process and stop the execution 两者工作相同,这会阻止进程并停止执行

and about your question there is one option return true; 关于您的问题,只有一个选项return true; to continue the execution of function. 继续执行功能。

I hope it will help to solve the problem. 我希望它将有助于解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM