惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - bela liu

生成PDF文档,并在PDF文档结尾加印章 EF CodeFirst 学习 1 - 用fluent API设置元数据, silverlight: 关于dataform的commit silverlight:datagrid滚动 win7下chm打不开 MS DTC 无法正确处理DC升级/降级事件。MS DTC 将继续运行并使用现有的安全设置。 远程桌面如果超出最大连接数, 使用命令行mstsc /console登录即可。 windows server 2008 安装live mail windows server 2008 安装 MSN Help: DCOM中设定"launch permission"的问题 Qt 学习(1) 现有一车(千里马)过年从苏州回赣榆,15号或者17号出发,21号,23号或者25号返程。 在Oracle中申明与某个字段类型相同的变量 几道Python的习题 在ReportViewer中使用超链接(HyperLink) 未解之Bug (1) : 必须放在具有 runat=server 的窗体标记内 在window.showModelessDialog打开的窗体中调用原窗体的alert会使IE死掉。 [转]面向对象与数据模型 在模式窗体中提交而不打开新窗体
使用firefox的一个小技巧 - bela liu - 博客园
bela liu · 2007-04-01 · via 博客园 - bela liu

今天帮别人写一个网页,发现:当用javascript动态设置tr.style.display = "block"显示某行时,使用IE浏览没有问题,但使用firefox浏览时该行被移到了其它行的后面,很是诧异。看下面这个例子:

<html>
<head>
    
<script type="text/javascript">
    
function body_load()
    {
        
var obj = document.getElementById("tr1");
        obj.style.display 
= "block";
    }
    
</script>
</head>
<body onload="javascript:body_load();">
    
<table>
        
<tbody id="tr1" style="display:none">
        
<tr>
            
<td>第一行</td>
        
</tr>
        
</tbody>
        
<tbody id="tr2">
        
<tr>
            
<td>第二行</td>
        
</tr>
        
</tbody>        
        
<tbody id="tr3">
        
<tr>
            
<td>第三行</td>
        
</tr>
        
</tbody>
    
</table>
</body>
</html>

它在firefox中显示时,“第一行”被显示在最后一行。

于是在处理好需要显示的行后,另写了一个函数,先记录需要显示的行,然后将所有行的style.display都设置为"none",最后再将需要显示的行依次显示出来。这样,IE和firefox的显示结果就一样了。

后来,我还是觉得这个方法很笨,就又潜心研究了一番,发现,只要将第二行和都三行都加上style="display:block",显示也就正常了。见下面的代码:

<html>
<head>
    
<script type="text/javascript">
    
function body_load()
    {
        
var obj = document.getElementById("tr1");
        obj.style.display 
= "block";
    }
    
</script>
</head>
<body onload="javascript:body_load();">
    
<table>
        
<tbody id="tr1" style="display:none">
        
<tr>
            
<td>第一行</td>
        
</tr>
        
</tbody>
        
<tbody id="tr2" style="display:block">
        
<tr>
            
<td>第二行</td>
        
</tr>
        
</tbody>        
        
<tbody id="tr3" style="display:block">
        
<tr>
            
<td>第三行</td>
        
</tr>
        
</tbody>
    
</table>
</body>
</html>

由此可见,firefox对是否设置style="display:block"是区别对待的,而IE作了适当的兼容处理。
结论和教训是:尽量使用标准做法,不要指望浏览器可以兼容。IE用多了就常常会忘记这点。

注:如果不使用tbody则没有这个问题。但tbody可以起到对行进行分组的作用,当一次需要显示或隐藏多行时很有用。