我想設置表格中單元格的高度,但我希望是動態的。我從JavaScript的窗口的高度,然後我想嵌入它的div風格。從javascript設置樣式值var
<script language="javascript">
var width = isNaN(window.innerWidth) ? window.clientWidth : window.innerWidth;
var height = isNaN(window.innerHeight) ? window.clientHeight : window.innerHeight;
if (height>900)
{
set_height = "500px";
} else if (height>700 && height<900) {
set_height = "400px";
} else if (height>500 && height<700) {
set_height = "300px";
} else if (height>300 && height<500) {
set_height = "300px";
}
</script>
<table border ="1">
<tr><td>
<div style="height: set_height">
</div>
</td></tr>
</table>
它可能嗎?
添加ID到你的'div',包你代碼在窗口加載函數,並使用'document.getElementById('yourdiv')。style.height = set_height'。 – putvande