[英]unresolved function or method JavaScript yii2
I want to print the contents of HTML
. 我想打印HTML
的内容。 For this I have created a function and in this function I have passed the div
ID in it. 为此,我创建了一个函数,并在该函数中传递了div
ID。 But the choose shown the following message. 但是选择显示以下消息。
My javascript
is under document.ready
function 我的javascript
在document.ready
函数下
function printDiv(divName) {
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
And here I am getting error Unused function printDev
这是我得到的错误Unused function printDev
I have tried to enable NodeJS and NPM but still no use 我试图启用NodeJS和NPM,但仍然没有用
Any help would be highly appreciated. 任何帮助将不胜感激。
My javascript is under document.ready function 我的JavaScript在document.ready函数下
If you defined the printDiv function inside another function, it's not visible to your onclick HTML parameter. 如果在另一个函数中定义了printDiv函数,则onclick HTML参数不可见。
You can either define it as a global function, or add an eventListener to your element inside your document.ready function : 您可以将其定义为全局函数,或者将eventListener添加到document.ready函数内的元素中:
function printDiv(divName) { var printContents = document.getElementById(divName).innerHTML; var originalContents = document.body.innerHTML; document.body.innerHTML = printContents; window.print(); document.body.innerHTML = originalContents; } $( document ).ready(function() { document.getElementById("printButton").addEventListener("click", function() { printDiv('print'); }); });
<!DOCTYPE html> <html lang="en"> <head> <script src="https://code.jquery.com/jquery-2.2.4.js"></script> </head> <body> <input type="button" id="printButton" value="Print PDF"></input> <div id="print"></div> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.