2011-05-24 210 views
0

我有一個函數應該顯示一個文本框,該文本框基於在下拉列表中選擇的選項。我已經在javascript中寫了這個,我也使用usercontrols。這裏是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'的情況。它跳過整個循環,並說變量'Objtr_lbl_Healthy_Family_Member_Number'沒有對象/未定義?

感謝您的幫助。

+0

你可以包含你的'createObj()'函數嗎? – Ben 2011-05-24 00:15:27

回答

0

IsValidObj正試圖訪問未定義的變量Objtr_lbl_Healthy_Family_Member_Number。

createObj不返回對象。

+0

是的。但爲什麼不呢?我在用戶控件中的文本框ID爲'tr_lbl_Healthy_Family_Member_Numbe',我正在爲此創建對象。那爲什麼它不返回對象?相同的代碼適用於正確顯示的另一個文本框。 – userstackoverflow 2011-05-24 00:36:53

+0

假設createObj的代碼是正確的,它們可能不是由您傳遞該方法的ID存在的元素。仔細檢查該文本框的ID與傳遞給該方法的內容。 – 2011-05-24 01:39:10

0

我第一次的猜測,沒有看到createObj()功能,是

  • 因爲Objtr_lbl_Healthy_Family_Member_Number是不是,是不是在DOM創建該元素有效的HTML標籤
  • 所以createObj()不能做任何東西(並且不會返回任何東西)
  • 因此var Objtr_lbl_Healthy_Family_Member_Number因此未定義。
+0

我使用相同的代碼來顯示相同​​的用戶控件中的另一個文本框,它的工作原理爲什麼不是這樣? – userstackoverflow 2011-05-24 00:38:19