gpt4 book ai didi

JavaScript 运行时错误 : Unable to get property 'innerHTML' of undefined or null reference in asp. 网络

转载 作者:行者123 更新时间:2023-11-30 13:03:37 25 4
gpt4 key购买 nike

我有一个文本框,用户可以在其中写一些文本。

现在如果他想打印那个文本,他应该点击打印按钮。打印按钮设计如下:

<asp:Button ID="btnPrint" runat="server" Text="Print" Enabled="False" OnClientClick = "CallPrint('txtReadFiles')" />

现在在 aspx 页面的头部,函数 CallPrint 声明如下:

<script type="text/javascript" language="javascript">
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
**var docwrite=prtContent.innerHTML;**
var WinPrint = window.open('','','left=0,top=0,toolbar=0,status=0');
WinPrint.document.open();
WinPrint.document.write(docwrite);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
}
</script>

但是当我点击打印按钮时,在标有 ** 的行上出现错误

JavaScript 运行时错误:无法获取未定义或空引用的属性“innerHTML”

这里有什么问题?

最佳答案

那可能是因为此行 var prtContent = document.getElementById(strid); 失败,即返回 null。您要获取的文本框也是服务器控件吗?如果是这样,那么在运行时它的 id 会改变,如果这确实是问题,请查看 here

关于JavaScript 运行时错误 : Unable to get property 'innerHTML' of undefined or null reference in asp. 网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16512336/

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