Use of getPreventDefault() is deprecated. Use defaultPrevented instead. Why I'm getting this error and what's the solution for it?

不问归期 提交于 2019-12-04 15:16:26

问题


Previously I was using jQuery 1.7.1 in my code. I was getting the above error. Then I used the jQuery 1.11.1 straight from the google repository

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js">
</script>

but still I'm getting this error. How should I resolve this?

Due to this error my other jQuery functionality is also not working.

I researched a lot about the solution but every time I got the same solution of upgrading the jQuery version. But this is also not working for me.


回答1:


Try:

event.originalEvent.defaultPrevented

As in:

$(document).on('click', function (e) {
    if (e.originalEvent.defaultPrevented) return;
    // continue
});



回答2:


I get this error with PHPStorm debugging with Firefox 2.8 when using jQuery, currently jquery-2.0.2.min. On examining the file, it contains the following statement:

this.isDefaultPrevented=e.defaultPrevented||e.getPreventDefault&&e.getPreventDefault()?U:Y

if you change this to:

this.isDefaultPrevented=e.defaultPrevented?U:Y

the warning stops.




回答3:


I have also come across this problem and found that with jQuery 1.x the replacement

event.defaultPrevented;

does not work at all, but the original

event.getPreventDefault();

still works as expected but does throw a warning on Firebug. I guess someone somewhere expects everyone to upgrade to jQuery 2.x eventually. This shouldn't be a fatal or critical error for you, simply a warning, and in this instance that the replacement feature doesn't work on jQuery 1.x then it's suitable to bare this in mind but not act upon this warning.




回答4:


I had the same issue and using Firefox's dev tools I realized I incorrectly commented something out in a hurry, forgetting to comment out the </script> also. Sometimes it the stupid little things.




回答5:


I suggest you to use the file locally. Then if the problem is still there, open your jquery file and search for "getPreventDefault" and replace by "defaultPrevented".




回答6:


kindly check if the jquery.min.js is included twice. if yes then try to ignore local one so that you get latest file. Actually I got same msg on myside so by debugging i found there were to jquery library was included twice. hope this will work for you.




回答7:


There is getPreventDefault in https://code.jquery.com/jquery-1.7.1.min.js

The list of all versions https://code.jquery.com/jquery/

getPreventDefault is still in 1.8.3, 1.9.1, 1.10.2, 1.11.0

And it's finally gone in 1.11.1 of which 1.11.3 is the latest version.



来源:https://stackoverflow.com/questions/26177305/use-of-getpreventdefault-is-deprecated-use-defaultprevented-instead-why-im

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!