[英]Change div height in Internet Explorer 7
I can't change the div
height in Internet Explorer 7 with this code, that works in other browsers.我无法使用此代码更改 Internet Explorer 7 中的div
高度,该代码适用于其他浏览器。
document.getElementById('my_div').setAttribute("style","height:1000px !important");
var clientHeight = document.getElementById('my_div').clientHeight;
You need to change this line你需要改变这一行
document.getElementById('my_div').setAttribute("style","height:1000px !important");
by经过
document.getElementById('my_div').style.height = '1000px';
This is a complete running example:这是一个完整的运行示例:
function changeDivHeight(){ var oldHeight = document.getElementById('my_div').clientHeight; console.log('old Height:', oldHeight); var val = document.getElementById('newHeight').value; document.getElementById('my_div').style.height = val + 'px'; var newHeight = document.getElementById('my_div').clientHeight; console.log('new Height:', newHeight); }
#my_div{ background-color: #d1d1f1; width: 400px; height: 20px; }
New height value <input id="newHeight" type="text" placeholder="New div height" /> <button onclick="changeDivHeight()">Change height</button> <div id="my_div"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.