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

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator 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可以起到对行进行分组的作用,当一次需要显示或隐藏多行时很有用。