Javascript 动态页面大小取决于内部菜单项的高度
我有一个菜单,其中有默认折叠的动态项目。我正在尝试使用更改项目折叠状态来更改页面高度Javascript 动态页面大小取决于内部菜单项的高度,javascript,asp.net,Javascript,Asp.net,我有一个菜单,其中有默认折叠的动态项目。我正在尝试使用更改项目折叠状态来更改页面高度 <script type="text/javascript"> function fun() { var iFrameID = document.getElementById('wrapper'); if (iFrameID) { // here you can make the height, I delete it
<script type="text/javascript">
function fun() {
var iFrameID = document.getElementById('wrapper');
if (iFrameID) {
// here you can make the height, I delete it first, then I make it again
iFrameID.height = "";
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
问题:iFrameID.contentWindow.document.body.scrollHeight+“px”;iFrameID.contentWindow未定义 您选择的是包装器(假设为div),而不是frame或iframe。 只有框架标记和iframe标记具有contentWindow属性 解决方案:
var iFrameObj = document.getElementById('iFrameId');
iFrameID.height = iFrameObj .contentWindow.document.body.scrollHeight + "px";
动态菜单可能不是在iframe中创建的!这里的代码是为了找到iframe内部的高度,而不是div的高度。你的答案是正确的(有效),但没有给出我的目标
Cannot read property 'document' of undefined
var iFrameObj = document.getElementById('iFrameId');
iFrameID.height = iFrameObj .contentWindow.document.body.scrollHeight + "px";