2011-03-04 54 views
1

我想動態地隱藏/取消隱藏多個錶行使用Javascript來模仿崩潰/展開。這裏是相關的代碼片段:IE7與rowspan當動態摺疊多行(底部額外的空間)

function selectionFilter(check, filter){ 
     var elem = document.getElementById('myScrollTable').rows; 
     for(i = 0; i < elem.length; i++){ 
      var type = elem[i].getAttribute('type'); 
      if(type== filter){ 
       if(check == true){ 
        elem[i].style.display=''; 
       }else{ 
        elem[i].style.display='none'; 
       } 
      } 
     } 
    } 

,這裏是樣本HTML:

<input type="checkbox" checked="true" value="t1" onclick="selectionFilter(this.checked, this.value);">some type 1</input > 
<input type="checkbox" value="t2" onclick="selectionFilter(this.checked, this.value);">some type 2</input ><br><br> 
<table cellspacing="1" cellpadding="2" class="" id="myScrollTable"> 
    <thead> 
     <tr> 
      <th>Data1</th> 
      <th>Data2</th> 
     </tr> 
    </thead> 

    <tbody> 
     <tr type="t1"> 
      <td rowspan="50"><a href="something1">something1</a></td><td><a href="something2">something2</a></td> 
     </tr> 
     <tr type="t1"> 
      <td><a href="something2">something2</a></td> 
     </tr> 
      . 
      . 
     <tr type="t2" style="display:none;"> 
      <td rowspan="50"><a href="something1">something1</a></td><td><a href="something2">something2</a></td> 
     </tr> 
     <tr type="t2" style="display:none;"> 
      <td><a href="something2">something2</a></td> 
     </tr> 
      . 
      . 
    </tbody> 
</table> 

在Firefox中,一切都很好。然而在IE中,第一次隱藏任何行之後,當它被隱藏時,它在底部附加了一些額外的空間。當不使用rowspan時不會發生這種情況。我嘗試了很多東西,但無法擺脫額外的空間。

我真的很感激,如果有人可以給我一些提示。

+0

可能不相關vant,但是在那個HTML樣例中,你似乎缺少'type =「t2」'附近的''標籤。 – thirtydot 2011-03-04 22:49:33

+0

感謝通知,這是真的。我即時編寫了這個例子,它可能不是一個真正的工作版本。 – amorteza 2011-03-07 15:21:32

回答

0

您是否嘗試過使用而不是空字符串?

你應該嘗試使用

elem[i].style.display = 'block'; 

如果失敗,你應該嘗試

elem[i].style.display = 'table-row'; 

和八方通應檢查W3Schools的文檔,它真的有用 http://www.w3schools.com/css/pr_class_display.asp

Tellme公司,如果這適合你

+0

感謝您的回覆。我嘗試過這些選項,但不幸的是我沒有運氣。旁邊我做了一些小的改變,提供的HTML代碼(從標記移動rowspan =「50」到​​,我的不好) – amorteza 2011-03-23 15:33:02