2010-02-04 66 views
1

如何找到輸入文本框是出口或沒有在我的iframe HTML窗口使用JavaScript如何在iframe窗口中找到輸入文本框?

現在,我使用下面的代碼

if(document.getElementById('iframe').contentWindow.document.getElementById("INPUTBOX").value) 
{ 
alert("Exist") 
} 
else 
{ 
alert("NOT Exist") 
} 

但它給了我

回答

1

你錯誤「所需的對象」需要從if語句的末尾刪除.value

if(document.getElementById('iframe') 
     .contentWindow.document.getElementById("INPUTBOX")) 
{ 
    alert("Exist"); 
} 
else 
{ 
    alert("NOT Exist"); 
} 

你所得到的「所需的對象」之所以錯誤是輸入框的頁面不存在,你還在嘗試訪問value屬性。訪問不存在的對象上的屬性將引發該錯誤。