2012-02-24 93 views
0

工作,我有以下的HTML代碼style.visibility JavaScript並不是在IE

     <tr id="maxHoursId"> 
          <td>MaxHours</td> 
          <td><input type="text" name="maxHours" size="5" value=""></td> 
          <td colspan="8"></td> 
         </tr>       

我打電話以下Java腳本在 ,但元件沒有得到隱藏在IE瀏覽器。它可以在Chrome中正常工作,Firefox

function hideMaxHours() { 
    var listingType = document.getElementById('listingTypeId').value; 
    if (listingType == "FullDay") { 
     var trId = document.getElementById('maxHoursId'); 
     trId.style.visibility = 'hidden'; 
    } 
} 
+0

如何確保你的是,如果條件是真的嗎?由於設置樣式爲我在IE工程:http://jsfiddle.net/UmL5M/ – nnnnnn 2012-02-24 23:40:47

+0

你說得對,看來控制未在側去,如果條件反正。那麼怎麼寫比較呢?我已經檢查了java教程,並根據它看起來像我所擁有的是正確的 – 2012-02-24 23:47:35

+0

您正在測試什麼版本的IE?這在IE9正常工作:http://jsfiddle.net/HH6Wd/ – pete 2012-02-24 23:49:55

回答

0

如何嘗試trId.style.display ='hidden';代替?當你希望它再次可見時,將其更改爲trId.style.display ='block';

+0

因爲'display:hidden'將不會是有效的CSS。 – 2012-02-25 12:39:33

+0

意思是寫'display:none' .. – 2012-02-27 01:26:22

0

我tryed

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<body> 
    <table> 
<tr id="maxHoursId"> 
          <td>MaxHours</td> 
          <td><input type="text" name="maxHours" size="5" value=""></td> 
          <td colspan="8"></td> 
         </tr>  
</table> 
<script> 
    var trId = document.getElementById('maxHoursId'); 
     trId.style.visibility = 'hidden'; 
</script> 
</body> 
</html> 

它工作在IE 8,IE6,7可能不支持TR隱藏,你可以橫置TD

-1

您正在嘗試文件得到機會之前隱藏的元素加載。

爲了處理這種情況,使用jQuery來執行你的函數。

例如:

 
    
    
    $(document).ready(function() {  
    function hideMaxHours() { 
    document.getElementById('listingTypeId').value; 
    if (listingType == "FullDay") { 
    var trId = document.getElementById("maxHoursId"); 
    trId.style.visibility = 'hidden'; 
    } 
    else { 
    alert("The value of listingType is" + listingType); 
    } 
    } 
    hideMaxHours() 
    });