为什么.style.display =“block”改变我的表的长度? [英] Why does .style.display="block" change the length of my table?

查看:152
本文介绍了为什么.style.display =“block”改变我的表的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表都有相同的类和结构的表。我用CSS样式的类,他们看起来就像我想要的。



问题是,如果这些表中的一个开始隐藏,并稍后使用JavaScript显示大纲



这是用于显示表格的代码:

  function setTable(){
if(document.getElementById(forfeitTable2)。style.display ==none){
document.getElementById( forfeitTable2)。style.display =block;
}
else if(document.getElementById(forfeitTable2)。style.display ==block){
document.getElementById(forfeitTable2)。style.display =none ;
}
}

这个演示可能会比我更好地解释:



http://jsfiddle.net/DelightedD0D / 6Ajyn / 1 /


  1. 为什么会发生这种情况?

  2. 要阻止它吗?


解决方案

/ p>

I have two tables that both have the same class and structure. I style the class with CSS and they look just like I want.

The problem is that if one of those tables starts off hidden and is later displayed using JavaScript the outline ive given it shrinks to wherever the text is that it surrounds.

this is the code used to display the table:

function setTable(){    
   if(document.getElementById("forfeitTable2").style.display=="none"){
      document.getElementById("forfeitTable2").style.display="block";
   }
   else if(document.getElementById("forfeitTable2").style.display=="block"){
      document.getElementById("forfeitTable2").style.display="none";
   }
}

This demo can probly explain it better than I can:

http://jsfiddle.net/DelightedD0D/6Ajyn/1/

  1. Why does this happen?
  2. What can I do to stop it?

解决方案

can you try setting display to table instead of block!

这篇关于为什么.style.display =“block”改变我的表的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆