js style动态设置table高度

前端之家收集整理的这篇文章主要介绍了js style动态设置table高度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

直接在table标签中设置下不就行了吗?这是静态的,如果要动态设置你会吗?

var contentsHeight = document.body.clientHeight;
var buttonsHeight = document.getElementById( "buttons" ).offsetHeight;
var head1Height = document.getElementById( "head1" ).offsetHeight;
var head2Height = document.getElementById( "head2" ).offsetHeight;

var t1 = document.getElementById( "TableContainer1" ).style.height;
var t2 = document.getElementById( "TableContainer2" ).style.height;

//alert(document.getElementById( "TableContainer1" ).style.height);
var h = contentsHeight - buttonsHeight - head1Height - head2Height - 13;
if(h < 110){
return;
}
document.getElementById( "TableContainer1" ).style.height = h/2 + 'px';
document.getElementById( "TableContainer2" ).style.height = h/2 + 'px';
}
function com_sbs_pagesize(){
var screenHeight = window.screen.height;
var availHeight = window.screen.availHeight;
//alert(document.getElementById( "TableContainer1" ).children[0].rows.length);
var index = document.getElementById( "TableContainer1" ).children[0].rows.length
var buttonsHeight = document.getElementById( "buttons" ).offsetHeight;
var head1Height = document.getElementById( "head1" ).offsetHeight;
var head2Height = document.getElementById( "head2" ).offsetHeight;

var mainH = buttonsHeight + head1Height +head2Height + 13;
//20:scroll 35:title 25:tr
while ((availHeight-mainH) < (20 + 35 + 25index)2)
{
index = index - 1;
}
var tableHeight = 20 + 35 + 25index;
document.getElementById( "TableContainer1" ).style.height = tableHeight + 'px';
document.getElementById( "TableContainer2" ).style.height = tableHeight + 'px';
window.resizeTo(document.body.offsetWidth,mainH + tableHeight
2);
}

原文链接:https://www.f2er.com/js/57477.html

猜你在找的JavaScript相关文章