Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态页面大小取决于内部菜单项的高度_Javascript_Asp.net - Fatal编程技术网

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";