jQuery 不推荐使用 getPreventDefault()。改用 defaultPrevented

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19175218/
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-26 23:22:21  来源:igfitidea点击:

Use of getPreventDefault() is deprecated. Use defaultPrevented instead

javascriptjqueryfirefoxprinting

提问by Mian Anjum

I want to Print receipt page on loading page in firefox

我想在 Firefox 的加载页面上打印收据页面

Firefox shows following error..

Firefox 显示以下错误..

Use of getPreventDefault()is deprecated. Use defaultPrevented instead. error source line:

使用的getPreventDefault()是过时了。请改用 defaultPrevented。错误源行:

src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse;

NS_ERROR_NOT_AVAILABLE: Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.print] error source line:

NS_ERROR_NOT_AVAILABLE:组件返回失败代码:0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIDOMWindow.print] 错误源行:



print();

code:

代码:

$(document).ready(function() {
    print_doc();
    $("#Submit").click(function() {
        $("#goBack").hide();
        $("#printRow").hide();
        print();
        $("#goBack").show();
        $("#printRow").show();
    });
});

function print_doc() {
    $("#goBack").hide();
    $("#printRow").hide();
    print();
    $("#goBack").show();
    $("#printRow").show();
}

I want to print my receipt before showing "goBack", and "printRow" id's but not working

我想在显示“goBack”和“printRow”ID 之前打印我的收据但不起作用

采纳答案by Shakti Patel

you can create new css with media type print

您可以使用媒体类型打印创建新的 css

<style media="print">
#goBack,#printRow {
   display:none;
}
</style>

used this code

使用此代码

print :

打印 :

Intended for printed documents (applies to docs viewed in print preview mode too).

用于打印文档(也适用于在打印预览模式下查看的文档)。

CSS Media Type

CSS 媒体类型

回答by MackieeE

Upgrade both your versions of Firefox& jQueryversion from 1.6.4to a more recent version.

将您的FirefoxjQuery版本升级1.6.4到更新的版本。

This was filed as a bug in Firefox in FF11 & Patched as a result:

这在 FF11 中作为 Firefox 中的一个错误提交并因此进行了修补:

Bug #707677: getPreventDefault(); deprecated

错误 #707677:getPreventDefault(); 已弃用

As after all, the error messages refer to lines of source code that are completely unrelated to your code.

毕竟,错误消息指的是与您的代码完全无关的源代码行。

回答by Matt

I also get this warning in the latest FF and jQuery. Don't worry about it, it'll get fixed upstream before it causes any problems.

我也在最新的 FF 和 jQuery 中收到此警告。别担心,它会在导致任何问题之前在上游得到修复。

As for your code, try this:

至于你的代码,试试这个:

$(document).ready(function() {
    $("#Submit").click(function() {
        var btns = $('#goBack, #printRow');
        btns.hide(function () {
            window.print();
            btns.show();
        });
    });
});

.hide() is asynchronous, meaning that the next line of code may be executed before the browser has had a chance to execute it. So you might be printing before the elements are hidden. By sticking the print inside of .hide()'s callback, you are sure it is hidden when you print.

.hide() 是异步的,这意味着下一行代码可能会在浏览器有机会执行之前执行。因此,您可能会在隐藏元素之前进行打印。通过将打印粘贴在 .hide() 的回调中,您可以确定打印时它是隐藏的。

As another poster mentioned, though, CSS media types are probably a better way to do this:

不过,正如另一位海报所提到的,CSS 媒体类型可能是实现此目的的更好方法:

@media print {
  #goBack, #printRow {
     display: none;
  }
}

回答by Bikram Shrestha

it resolved by replacing the latest version of js , visit jquery site and replace with the latest jquery if required .map js too

它通过替换最新版本的 js 来解决,访问 jquery 站点并根据需要替换为最新的 jquery .map js