다른 해상도에서 유동적으로 만들기 위해 테이블 너비/높이를 정의하는 데 사용하려고하는 JavaScript가 있습니다. 너비에 대해서는 잘 작동하는 것처럼 보이지만 높이에 대해서는 작동하지 않습니다. 올바른 숫자를 올바른 변수로 설정하면 테이블의 높이를 설정하지 않습니다. 여기에 내가 무엇을 가지고 ..테이블 너비/높이를 결정하는 자바 스크립트
<html>
<head>
<script type="text/javascript">
var viewportwidth;
var viewportheight;
var tablewidth;
var tableheight;
if (typeof window.innerWidth != 'undefined'){ //set's viewport width/height into respective variables
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0){
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}else{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
function asdf(){
tablewidth = Math.round(viewportwidth/100*70); //sets table width to 70% of viewport width
tableheight = Math.round(tablewidth/100*74); //sets table height to 74% of table width, this number is ambigous
document.getElementById('poop').innerHTML = tableheight+', '+tablewidth+', viewport width is '+viewportwidth+'x'+viewportheight;
document.getElementById('container').width = tablewidth;
document.getElementById('container').height = tableheight;
}
</script>
</head>
<body onload="asdf();">
<span id="poop"></span>
<table id="container" cellpadding="0" border="1" cellspacing="0" width="" height="">
<tr><td colspan="5"></td></tr>
<tr>
<td width="38%"></td>
<td width="12%"></td>
<td width="21%"></td>
<td width="14%"></td>
<td width="15%"></td>
</tr>
</table>
</body>
</html>
누구나 내가 뭘 잘못하고 있는지 보여?
테이블에 스타일이없는 경우 -------------> var width = document.getElementById ('TableID'). offsetWidth; –