gpt4 book ai didi

javascript - 当用户尝试以 Angular 打印时,有没有办法触发功能?

转载 作者:行者123 更新时间:2023-12-03 07:23:51 26 4
gpt4 key购买 nike

我正在使用打印元素函数来打印 SPA 中的 View 。当 View 更改时,该函数将运行并获取 View 。但是,如果用户更改页面上的某些内容,它不会更新,并且当您尝试打印时,您将获得与页面首次加载时相同的 View 。这是我正在使用的功能:

var printElement = function (elem, append, delimiter) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");

if (!$printSection) {
$printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}

if (append !== true) {
$printSection.innerHTML = "";
}

else if (append === true) {
if (typeof (delimiter) === "string") {
$printSection.innerHTML += delimiter;
}
else if (typeof (delimiter) === "object") {
$printSection.appendChlid(delimiter);
}
}
$printSection.appendChild(domClone);
};

我的问题是,当有人使用浏览器打印功能时,例如Ctrl+P,我是否可以触发此功能,以便当他们去打印页面时,页面会被更新?

最佳答案

您可以使用默认的 JavaScript 事件。既然您提到您正在使用 jQuery:

$(document).bind("keydown keyup", function(e){
if(event.ctrlKey && event.keyCode == 80){
// CTRL+P was pressed.
}
});

关于javascript - 当用户尝试以 Angular 打印时,有没有办法触发功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36088984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com