【问题标题】:jQuery warning: event.returnValue is deprecated. Please use the standard event.preventDefault() instead [duplicate]jQuery 警告:不推荐使用 event.returnValue。请改用标准 event.preventDefault() [重复]
【发布时间】:2013-11-29 07:34:41
【问题描述】:

这是 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 中返回一个非空字符串

【问题讨论】:

    标签: jquery


    【解决方案1】:

    这是bug

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

    【讨论】:

      【解决方案2】:

      这不是错误...

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

      这有一个 jquery.com open ticket

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-12-01
          • 1970-01-01
          • 1970-01-01
          • 2014-09-28
          • 1970-01-01
          • 2021-08-09
          • 1970-01-01
          相关资源
          最近更新 更多