jQuery 警告:不推荐使用 event.returnValue。请改用标准 event.preventDefault()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20280570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 01:05:44  来源:igfitidea点击:

jQuery warning: event.returnValue is deprecated. Please use the standard event.preventDefault() instead

jquery

提问by sindhuri

this is sindhuri,I receive the following warning in my Google Chrome console: event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery1.9.1 version i am using.

这是 sindhuri,我在 Google Chrome 控制台中收到以下警告:不推荐使用 event.returnValue。请改用标准 event.preventDefault()。我正在使用 jquery1.9.1 版本。

<script>
window.jQuery(document).ready(function () {
    window.jQuery('#hideshow').click(function () {
        window.jQuery('#message').toggle(function () {
            window.jQuery('#hideshow').text('Show');
            window.jQuery('#message').hide();
            alert("message hide succeesfully");
        }),
        function () {
            window.jQuery('#hideshow').text('Hide');
            window.jQuery('#message').show();

            alert("message show succeesfully");
        }
    });
});
</script> <a href="#" id="hideshow">Hide</a>
BeforeUnloadEvent 有一个 returnValue 属性。在事件处理程序中将 returnValue 设置为非空字符串会导致用户代理应要求用户确认他们希望卸载文档。这相当于在 EventHandler 中返回一个非空字符串

回答by Tushar Gupta - curioustushar

It's a bug

这是一个错误

This is only a warning message your code will still work.

这只是一条警告消息,您的代码仍然可以工作。

回答by elad silver

this is not a bug...

这不是错误...

just use the latest version thats going to come out soon (1.11) and you'll be fine

只需使用即将推出的最新版本(1.11)就可以了

this has a jquery.com open ticket:

这有一张jquery.com 公开票

The bug is fixed in what will become 1.11/2.1. The duplicate bug ticket #14282 explains this. It also explains that older versions of jQuery will give this warning eternally.

该错误在将成为 1.11/2.1 的版本中得到修复。重复的错误票 #14282 解释了这一点。它还解释了旧版本的 jQuery 将永远发出此警告。

回答by Deepesh

Code will work but in some condition another event is fire because of that warning. And your output will effect somewhere in view page(Probably with jquery ajax call).

代码将工作,但在某些情况下,由于该警告,另一个事件被触发。并且您的输出将影响视图页面中的某处(可能与 jquery ajax 调用)。