最佳答案
做到这一点的最简单、最好的方法是使用一个名为 jQuery 的库。它可以让您编写更少的代码,并为您提供大量预编写的功能。
首先,在 <head>
中包含 jQuery或者在你的 <body>
的底部您的 HTML 文件:
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
接下来,您将要使用此 JavaScript。确保它低于 <script>
jQuery 的标记,否则它将不起作用:
$(document).ready(function()
{
$theDiv = $('#theid'); // #theid should be the `id` attribute of the div you are trying to modify
$theDiv.css({'height': '57px'}); // the height can be set to whatever you want
$theDiv.attr('detailsVisible', true);
});
您还可以运行 $(document).ready();
中的特定代码每当您需要时,例如当您单击按钮等时。上面的特定代码会在页面准备好后立即运行。
关于javascript - 如何在加载时使用 javascript 设置高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34958825/