无法设置属性'高度'的未定义
Cannot set property 'height' of undefined
我试图通过从另一个div
获取height
来更改div
的height
,但我得到了错误Cannot set property 'height' of undefined
。
代码:
$("#loading_image_container").style.height = $('#content_frame').height();
我确信content_frame的高度是500px。
尝试
$("#loading_image_container").height($('#content_frame').height());
因为您引用的是jQuery对象,而不是DOM元素。使用内置的jQuery函数如下:
$("#loading_image_container").height($('#content_frame').height());
或者,首先获取DOM元素:
$("#loading_image_container")[0].style.height = $('#content_frame').height();
您正试图设置jQuery对象的style
,请使用CSS
$("#loading_image_container").css("height", $('#content_frame').height());
或者:
$("#loading_image_container")[0].style.height = $('#content_frame').height();
试试这个:
$(".div1").css({'height':($(".div2").height()+'px')});
也许您错过了正确表达式中的.style:尝试
$("#loading_image_container").style.height = $('#content_frame').style.height;
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- Javascript图像宽度和高度未定义值
- 无法设置属性'高度'的未定义
- 具有初始未定义高度的jQueryui动画
- 是否可以使用jQuery来查找高度未定义的文本跨度的高度
- 宽度和高度未定义- Javascript/jQuery