---
title: "firefox显示隐藏的tr"
author: "floydd"
date: "2008-01-31T13:37:00Z"
tags: []
slug: "firefox-tr"
draft: false
lastmod: "2011-12-26T12:03:12Z"
id: 1326381
url: "https://floydd.iteye.com/blog/1326381"
---

以下这段代码在ie下工作的很好，可是ff不行；

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)functiontoggleTableRow()...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)vartr1=document.getElementById('tr1');  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(tr1.style.display=='none')...tr1.style.display='block';  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)else... tr1.style.display='none';  
returnfalse;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}

哪里错了呢：if (tr1.style.display=='none') {tr1.style.display='block';} 这行吧block 改成 table-row 就好了。  
ff对table的tr的display定义比较规范严格，所以需要设置tr1.style.display='table-row';当然也可以简单的这样设置tr1.style.display=‘’，意思是设置为默认的现实属性，而不是block.

为什么ie是好呢？网上说是因为ie能够修正你设置的 类block元素 的display属性（设置错了也不要紧:(）  
具体看这里：http://rubyol.javaeye.com/blog/140870