用javascript打印问题…Div是一个空字符串
Printing with javascript problems.....div comes as a null string
我正在使用javascript函数来打印页面。我不断得到字符串作为一个空值,我不知道如何.....下面是代码。div我有被称为divSheet和它的设置为可见的false开始…当您加载信息时,它会在divSheet中创建一个表并将其设置为true。有人知道为什么它说在getPrint函数的条纹是空的吗?谢谢你!
<asp:ImageButton runat="server" ID="imageBtnPrint" Style="z-index: 100" ImageUrl="~/Images/printerIcon.gif"
OnClientClick="javascript:getPrint('divSheet')" ToolTip="Print" />
function getPrint(strid)
{
var pp = window.open();
var prtContent = document.getElementById(strid);
pp.document.writeln('<HTML><HEAD><title>Print Confirmation Sheet</title><LINK href=PrintStyle.css type="text/css" rel="stylesheet">')
pp.document.writeln('<LINK href=PrintStyle.css type="text/css" rel="stylesheet" media="print"><base target="_self"></HEAD>')
pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">');
pp.document.writeln('<form method="post">');
pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
pp.document.writeln(document.getElementById(strid).innerHTML);
pp.document.writeln('</form></body></HTML>');
}
我认为这是因为你是从主HTML生成子窗口,并且子页面不能直接访问父页面的变量。
你可以在父HTML中设置一个局部变量为div的ID,然后从JS函数中使用:window.opener.<variable name>
像这样:(警告:未测试)
...
var divId;
function getPrint(strid)
{
divId = strid;
var pp = window.open();
var prtContent = document.getElementById(window.opener.divId);
...
...
}
相关文章:
- NodeJS在一个较大的字符串中获取一个字符串的索引
- Javascript:用while循环在给定的count参数中重复一个字符串
- 如何使用另一个字符串作为模板从字符串中提取数据
- 如何检查一个字符串的所有字符是否都存在于另一个字符串中
- 从表单中动态生成一个字符串,传递给通过AJAX加载的PHP文件
- 我可以使用JS一次使用JSON数组中的一个字符串吗
- 将字符串转换为数组使用javascript更新一个值并返回一个字符串
- 如何在JavaScript中每隔第n个字符分割一个字符串
- 我需要使用什么语法来向一个对象的成员添加一个临时数组,该成员等同于一个字符串的通用列表
- 使用Jquery从所有元素创建一个字符串
- 在Javascript中截断一个字符串,混淆了最后两个测试字符串
- Javascript使用本地存储,回调对象并用Json更改为一个字符串以用于填充函数
- 将一个字符串数组解析为一个新的数组javascript
- 我可以在两个javascript文件之间传递一个字符串吗?
- 如何拆分一个字符串,然后将它们与另一个字符串匹配
- get没有方法“writefile”,即使输入是一个字符串
- 将 url 中的一个字符串替换为另一个字符串
- 如何在 javascript 中使用正则表达式在其他两个字符串之间找到一个字符串
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- 递归查找嵌套数组中的最后一个字符串