JavaScript 函数中未定义对象
我有一个函数应该根据下拉列表中选择的选项显示文本框。我用 javascript 写了这个,我也在使用用户控件。这是javascript函数的部分代码。
function showhideeffectivedate(objIncType)
{
var inctype=objIncType.value;
if(inctype=='AMC'||inctype=='AMCW'||inctype=='CMC'||inctype=='CMCHF'||inctype=='CHF')
{
var Objtr_lbl_Healthy_Family_Member_Number = createObj("tr_lbl_Healthy_Family_Member_Number");
if(IsValidObj(Objtr_lbl_Healthy_Family_Member_Number))
{
if(inctype=='CHF')
{
HideAreaCrossBrowser('tr_lbl_Healthy_Family_Member_Number',false)
}
else
HideAreaCrossBrowser('tr_lbl_Healthy_Family_Member_Number',true)
healthyfamilyMemberCheck()
}
}
else
{
var Objtr_lbl_Healthy_Family_Member_Number = createObj('tr_lbl_Healthy_Family_Member_Number');
if(IsValidObj(Objtr_lbl_Healthy_Family_Member_Number))
{
HideAreaCrossBrowser('tr_lbl_Healthy_Family_Member_Number',true)
}
}
}
包含控件/文本框的 .ascx 文件代码:
<tr class="Content" id="tr_lbl_Healthy_Family_Member_Number">
<td valign="top" colspan="2">
<table cellspacing="0" border="0">
<tr>
<td class="Content" align="right" id="td_lbl_Healthy_Family_Member_Number" width="130px">
<asp:Label ID="lbl_Healthy_Family_Member_Number" CssClass="Content" runat="server" Text="Healthy Family Member Number" />
</td>
<td class="Content" align="left" id="td_txt_Healthy_Family_Member_Number" width="185px">
<%--<asp:HiddenField runat="server" Value="td_txt_Healthy_Family_Member_Number" ID="hdn_help_11999" />--%>
<asp:TextBox ID="txt_Healthy_Family_Member_Number" CssClass="inputbox" onblur="" runat="server"
Enabled="True" />
</td>
</tr>
</table>
</td>
</tr>
我尝试调试此代码。此代码不检查“CHF”的 if 条件。它跳过整个循环并说变量“Objtr_lbl_Healthy_Family_Member_Number”没有对象/未定义?
感谢您的帮助。
I have a function which should display a textbox based on an option selected in a dropdown list. I have writen this in javascript, also I am using usercontrols. here is the partical code of javascript function.
function showhideeffectivedate(objIncType)
{
var inctype=objIncType.value;
if(inctype=='AMC'||inctype=='AMCW'||inctype=='CMC'||inctype=='CMCHF'||inctype=='CHF')
{
var Objtr_lbl_Healthy_Family_Member_Number = createObj("tr_lbl_Healthy_Family_Member_Number");
if(IsValidObj(Objtr_lbl_Healthy_Family_Member_Number))
{
if(inctype=='CHF')
{
HideAreaCrossBrowser('tr_lbl_Healthy_Family_Member_Number',false)
}
else
HideAreaCrossBrowser('tr_lbl_Healthy_Family_Member_Number',true)
healthyfamilyMemberCheck()
}
}
else
{
var Objtr_lbl_Healthy_Family_Member_Number = createObj('tr_lbl_Healthy_Family_Member_Number');
if(IsValidObj(Objtr_lbl_Healthy_Family_Member_Number))
{
HideAreaCrossBrowser('tr_lbl_Healthy_Family_Member_Number',true)
}
}
}
the .ascx file code which contains the control/textbox:
<tr class="Content" id="tr_lbl_Healthy_Family_Member_Number">
<td valign="top" colspan="2">
<table cellspacing="0" border="0">
<tr>
<td class="Content" align="right" id="td_lbl_Healthy_Family_Member_Number" width="130px">
<asp:Label ID="lbl_Healthy_Family_Member_Number" CssClass="Content" runat="server" Text="Healthy Family Member Number" />
</td>
<td class="Content" align="left" id="td_txt_Healthy_Family_Member_Number" width="185px">
<%--<asp:HiddenField runat="server" Value="td_txt_Healthy_Family_Member_Number" ID="hdn_help_11999" />--%>
<asp:TextBox ID="txt_Healthy_Family_Member_Number" CssClass="inputbox" onblur="" runat="server"
Enabled="True" />
</td>
</tr>
</table>
</td>
</tr>
I tried to debug this code. This code does not check for if condition of 'CHF'. It skips the entire loop and says that the variable 'Objtr_lbl_Healthy_Family_Member_Number' has no object/undefined?
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IsValidObj 正在尝试访问未定义的变量 Objtr_lbl_Healthy_Family_Member_Number。
createObj 不返回对象。
IsValidObj is attempting to access the variable Objtr_lbl_Healthy_Family_Member_Number which is undefined.
createObj is not returning an object.
在没有看到 createObj() 函数的情况下,我的第一个猜测是,
createObj()
无法执行任何操作(并且不会返回任何内容),var因此 Objtr_lbl_Healthy_Family_Member_Number
未定义。My first guess, without seeing the
createObj()
function, is thatObjtr_lbl_Healthy_Family_Member_Number
is not a valid HTML tag name, that element is not being created in the DOMcreateObj()
can't do anything (and won't return anything)var Objtr_lbl_Healthy_Family_Member_Number
is therefore undefined.