以下代码需要JavaScript解释!!! [英] JavaScript Explanation Required for the Following Code !!!

查看:95
本文介绍了以下代码需要JavaScript解释!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
我在我的朋友的一个Example中找到了这个JavaScript函数.
有人可以详细说明这个功能吗?

Dear Friends,
I found this JavaScript function on a Example of my friend.
Can someone plz explain me this function in details ?

function callPrint(elementId) {
                var prtContent = document.getElementById(elementId);
                var WinPrint = window.open('', '', 'left=0,top=0,width=1000,height=600,toolbar=2,scrollbars=2,status=0');
                var docColor = "Black";
                var strInnerHTML = prtContent.innerHTML;
                var strModifiedInnerHTMl = strInnerHTML.replace(/white/g, docColor);
                WinPrint.document.write(strModifiedInnerHTMl);
                WinPrint.document.close();
                WinPrint.focus();
                WinPrint.print();
                WinPrint.close();
            }   



我需要从第三行开始的解释.

感谢您的帮助.



I need Explanation from 3rd line Onward.

Thanks For Helping.

推荐答案

var docColor = "Black"


创建一个名为docColor的变量并将其值设置为字符串"Black"


Create a variable named docColor and set its value to the string "Black"

var strInnerHTML = prtContent.innerHTML;


创建一个名为strInnerHTML的变量,并将其值设置为prtContent页面元素的innerHTML值.


Create a variable named strInnerHTML and set its value to the innerHTML value of the prtContent page element.

var strModifiedInnerHTMl = strInnerHTML.replace(/white/g, docColor);


创建一个名为strModifiedInnerHTML的变量,并将其值设置为strInnerHTML的修改后的副本,在该副本中,"white"的所有实例均已替换为docColor(当前为"Black")的当前值.这是通过带有g开关的正则表达式/white/完成的,该开关表示它将更新找到的所有实例.


Create a variable named strModifiedInnerHTML and set its value to a modified copy of strInnerHTML where any instances of "white" have been replaced by the current value of docColor(Which is currently "Black"). This is being done with a regular expression /white/ with a g switch indicating that it will update all instances that it finds.

WinPrint.document.write(strModifiedInnerHTMl);


将strModifiedInnerHTML字符串写入WinPrint文档对象.


Writes the strModifiedInnerHTML string to a WinPrint document object.

WinPrint.document.close();


关闭WinPrint文档


Closes the WinPrint document

WinPrint.focus();


赋予WinPrint对象焦点


Gives the WinPrint object focus

WinPrint.print();


将Winprint对象发送到打印机


Sends the Winprint object to the printer

WinPrint.close();


关闭/完成WinPrint对象.很有可能需要执行此调用来清理WinPrint对象执行其操作所需的资源.


Closes/Finished the WinPrint object. More than likely this call is required to clean up resources that the WinPrint object required to perform its actions.


这篇关于以下代码需要JavaScript解释!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆