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
jQuery warning: event.returnValue is deprecated. Please use the standard event.preventDefault() instead
提问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
回答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 调用)。