JavaScript函数中的对象未定义

时间:2011-05-24 00:11:47

标签: javascript asp.net user-controls

我有一个功能,应根据下拉列表中选择的选项显示文本框。我在javascript中写了这个,我也在使用usercontrols。这是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" />&nbsp;
                                </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'的条件。它会跳过整个循环并说变量'Objtr_lbl_Healthy_Family_Member_Number'没有对象/未定义?

感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

IsValidObj正在尝试访问未定义的变量Objtr_lbl_Healthy_Family_Member_Number。

createObj没有返回对象。

答案 1 :(得分:0)

我的第一个猜测是,没有看到createObj()函数,就是那个

  • 由于Objtr_lbl_Healthy_Family_Member_Number不是有效的HTML标记名称,因此未在DOM中创建该元素
  • 所以createObj()无法做任何事情(并且不会返回任何内容)
  • 因此var Objtr_lbl_Healthy_Family_Member_Number未定义。