gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:32:22 26 4
gpt4 key购买 nike

我写了一个 javascript 代码来比较来自 2 个文本框的 2 个日期

     function CompareDates() {
var fdate = document.getElementById('txtFromDate');
var edate = document.getElementById('txtToDate');
var FromDate = fdate.value.split('/');
var EndDate = edate.value.split('/');
var val = 'false';

if (parseInt(FromDate[2]) < parseInt(EndDate[2])) {
val = 'true';
return true;
}
else if (parseInt(FromDate[2]) == parseInt(EndDate[2])) {
if (parseInt(FromDate[0]) < parseInt(EndDate[0])) {
val = 'true';
return true;
}
else if (parseInt(FromDate[0]) == parseInt(EndDate[0])) {
if (parseInt(FromDate[1]) <= parseInt(EndDate[1])) {
val = 'true';
return true;
}
}
}
if (val == "false") {
alert("FromDate Always Less Than ToDate");
return false;
}
}

html代码是

     <asp:TextBox ID="txtFromDate" runat="server" Width="150px" />
<ajaxToolkit:CalendarExtender CssClass="MyCalendar" runat="server"
ID="ceFromDate"
TargetControlID="txtFromDate"
Format="dd/MM/yyyy" />
<asp:TextBox ID="txtToDate" runat="server" Width="150px" />
<ajaxToolkit:CalendarExtender CssClass="MyCalendar" runat="server"
ID="ceToDAte"
TargetControlID="txtToDate"
Format="dd/MM/yyyy" />

<asp:Button ID="btnGenerate" runat="server" CssClass="button"
Text="Generate" OnClientClick="if(!CompareDates()) return false;"
OnClick="btnGenerate_Click" />

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

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

请帮助我克服这个问题。

最佳答案

错误在这里:

    var fdate = document.getElementById('txtFromDate');
var edate = document.getElementById('txtToDate');

问题是txtFromDatetxtToDate 是控件的服务器名称,而不是客户端名称(从浏览器查看页面源)。

试试这个:

    var fdate = document.getElementById('<%=txtFromDate.ClientID%>');
var edate = document.getElementById('<%=txtToDate.ClientID%>');

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

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