javascript设置表格的宽度和高度

JavaScript020

javascript设置表格的宽度和高度,第1张

window.outerheight

窗口总高度

和window.screen.availheight一样

window.innerheight

窗口可视区域高度

window.screen.height

显示器屏幕高度

另外:jquery获取高度

$(".thiscrumbs").height()

元素本身高度

$(".thiscrumbs").innerheight()

元素高度+内边距

$(".thiscrumbs").outerheight()

元素高度+内边距+边框

$(".thiscrumbs").outerheight(true)

元素高度+内边距+边框+外边距

你试试看

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>请调整浏览器窗口 </title><meta http-equiv="content-type" content="text/htmlcharset=gb2312">

</meta></head>

<body>

<h2 align="center">请调整浏览器窗口大小 </h2><hr />

<form action="#" method="get" name="form1" id="form1">

<!-- 显示浏览器窗口的实际尺寸 -->

浏览器窗口 的 实际高度 : <input type="text" name="availHeight" size="4"/><br />

浏览器窗口 的 实际宽度 : <input type="text" name="availWidth" size="4"/><br />

</form>

<script type="text/javascript">

<!--

var winWidth = 0

var winHeight = 0

function findDimensions() // 函数:获取尺寸

{

// 获取窗口宽度

if (window.innerWidth)

winWidth = window.innerWidth

else if ((document.body) &&(document.body.clientWidth))

winWidth = document.body.clientWidth

// 获取窗口高度

if (window.innerHeight)

winHeight = window.innerHeight

else if ((document.body) &&(document.body.clientHeight))

winHeight = document.body.clientHeight

// 通过深入 Document 内部对 body 进行检测,获取窗口大小

if (document.documentElement &&document.documentElement.clientHeight &&document.documentElement.clientWidth)

{

winHeight = document.documentElement.clientHeight

winWidth = document.documentElement.clientWidth

}

// 结果输出至两个文本框

document.form1.availHeight.value= winHeight

document.form1.availWidth.value= winWidth

if(winWidth <1000){

document.getElementById("table_m").width="1000"

}else{

document.getElementById("table_m").width = "100%"

}

}

findDimensions()

// 调用函数,获取数值

window.onresize=findDimensions

//-->

</script>

<table id="table_m" width="100%"><tr><td width="206" height="200">固定 <img src="" width="10" /></td><td width="100%" align="center"><table border="0" cellspacing="0" vspace="0" width="95%"><tr><td align="center" height="190" bgcolor="#999999">可变</td></tr></table></td><td width="206">固定<img src="" width="10" /></td></tr></table>

</body>

</html>