Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 与少校一起进行越位测试_Javascript_Offsetheight - Fatal编程技术网

Javascript 与少校一起进行越位测试

Javascript 与少校一起进行越位测试,javascript,offsetheight,Javascript,Offsetheight,我对一些简单的javascript内容很着迷 我需要一个简单的javascript来测试一个表的远视,以友好地设置它的div容器 我可以得到桌面高度的正确值,但“如果”条件不起作用 代码如下: var tableHeight = parseInt(document.getElementById("tableData").offsetHeight); if ( tableHeight>250 ) { document.getElementById("tableCont

我对一些简单的javascript内容很着迷

我需要一个简单的javascript来测试一个表的远视,以友好地设置它的div容器

我可以得到桌面高度的正确值,但“如果”条件不起作用

代码如下:

var tableHeight = parseInt(document.getElementById("tableData").offsetHeight);

if ( tableHeight>250 ) 
     {
     document.getElementById("tableContainer").style.height = "250px";
     } 

else 
{
BLABLBLABLA
 }

有什么建议吗?谢谢大家

我刚刚测试了你们的代码,效果很好

下面是一个JSFIDLE:

也许你忘了给表id,试着在if中登录控制台

if ( tableHeight>250 ) {
 console.log('more than 250');
}
似乎有效。控制台上有错误吗?