JavaScript 函数中未定义对象

发布于 2024-11-09 03:30:20 字数 2448 浏览 0 评论 0原文

我有一个函数应该根据下拉列表中选择的选项显示文本框。我用 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" />&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”的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掩于岁月 2024-11-16 03:30:20

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.

完美的未来在梦里 2024-11-16 03:30:20

在没有看到 createObj() 函数的情况下,我的第一个猜测是,

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

My first guess, without seeing the createObj() function, is that

  • since Objtr_lbl_Healthy_Family_Member_Number is not a valid HTML tag name, that element is not being created in the DOM
  • so createObj() can't do anything (and won't return anything)
  • so var Objtr_lbl_Healthy_Family_Member_Number is therefore undefined.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文