我想根据另一个 div 的高度设置一个 div 的高度,该高度根据浏览器宽度而变化。我写了以下我认为有道理但不起作用的东西,所以我不确定是否有办法做到这一点?
$(window).on('resize', function() {
var newHeight = $("#div1").height();
$("div2").css(height, newHeight);
});
谢谢
最佳答案
你的代码有两个问题
1) 您需要在引号中写 CSS 属性名称。
2) 你缺少 div2 的 ID 选择器
$("#div2").css('height',newHeight);
关于javascript - 使用变量在 jQuery 中设置 css 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998595/