考虑以下问题,
<div id="outerDIV">
<div id="innerDIV" style="height: 100%;">
<asp:ContentPlaceHolder... />
</div>
</div>
这些 DIV 驻留在 asp.net 站点的母版页中。我想编写一个函数来复制 innerDIV 的高度并将其应用于 outerDIV 的高度。我可以正常执行此操作,如下所示:
$(document).ready(function () {
$('#outerDIV').height($('#innerDIV').height());
});
但问题是我只希望它在页面的第一次加载时发生。当用户导航到其他页面时,我不希望 outerDIV 再次调整大小。
我怎样才能做到这一点?
谢谢
最佳答案
来自 MDN Docs : 将类选择器与您的 ID 选择器结合使用。
$(document).ready(function(){
$('#outerDIV.firstpage').height($('#innerDIV.firstpage').height());
}
});
通过添加 class='firstpage'
选择器,您可以区分您的首页和其他页面,而无需担心 cookie 或跟踪其他变量。
关于javascript - 在jquery中,如何编写一个函数将一个DIV的高度一次复制到另一个DIV?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28614459/