gpt4 book ai didi

JavaScript 运行时错误 : Unable to get property 'value' of undefined or null reference

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:22 24 4
gpt4 key购买 nike

我写了一个 javascript 代码来显示特定日历的下一个日期

我的函数

function verificaDataReferencia(mensagem)
{
if(document.getElementById("txtDataReferencia1Hidden") == null || document.getElementById("txtDataReferencia2Hidden") == null || document.getElementById("ddlDataPub") == null || document.getElementById("txtDataRefInfo") == null)

var objtxtDataReferencia1Hidden = document.getElementById("txtDataReferencia1Hidden").value;

var objtxtDataReferencia2Hidden = document.getElementById("txtDataReferencia2Hidden").value;

> Breakpoint var objtxtDataArquivo = document.getElementById("ddlDataPub").value;

var mensagem = document.getElementById("txtDataRefInfo").value;
if((objtxtDataReferencia1Hidden == objtxtDataArquivo) || (objtxtDataReferencia2Hidden == objtxtDataArquivo))
{
var x = alert(mensagem);
return x;
}
}

HTML

<asp:TextBox style="Z-INDEX: 112; POSITION: absolute; TOP: 9px; LEFT: 572px" id="txtDataReferencia1Hidden"
runat="server" CssClass="inputLabel" Width="15" Height="15px"></asp:TextBox>
<asp:TextBox style="Z-INDEX: 113; POSITION: absolute; TOP: 9px; LEFT: 606px" id="txtDataReferencia2Hidden"
runat="server" CssClass="inputLabel" Width="14" Height="14px"></asp:TextBox>

问题是页面在 chrome 中运行良好,但是当我在 IE 中运行我的应用程序时它抛出错误

0x800a138f - JavaScript runtime error: Unable to get property 'value' of undefined or null reference

请帮助我克服这个问题。

private void Page_Load(object sender, System.EventArgs e)
{

if(! IsPostBack)
{
txtNomePortugues.SetFocus();
BO.Pasta pasta = new BO.Pasta(CodPasta);
if (CodigoArquivo == 0 && !IsJustificativa && pasta.EnviaEmail)
btnGravar.Attributes.Add("onclick", "verificaDataReferencia(); confirmaEnvioEmail('" + GetString("Mensagem_Confirmacao_Alerta_Arquivos") + "');");
else
btnGravar.Attributes.Add("onclick", "verificaDataReferencia();");

最佳答案

问题在这里:

var mensagem = document.getElementById("txtDataRefInfo").value;
var objtxtDataReferencia1Hidden = document.getElementById("txtDataReferencia1Hidden").value;
var objtxtDataReferencia2Hidden = document.getElementById("txtDataReferencia2Hidden").value;

原因是 txtDataRefInfotxtDataReferencia1HiddentxtDataReferencia2Hidden 是服务器端控件而不是客户端。试试这个:

var objtxtDataReferencia1Hidden = document.getElementById('<%=txtDataReferencia1Hidden.ClientID%>');
var objtxtDataReferencia2Hidden = document.getElementById('<%=txtDataReferencia2Hidden.ClientID%>');
var mensagem = document.getElementById('<%=txtDataRefInfo.ClientID%>');

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

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