如何在加载时使用javascript设置高度

时间:2016-01-23 02:08:24

标签: javascript html css

如何在载荷上设置高度和可见度(detailsVisible)?提前谢谢。

从这里开始:

from here

到这里:

to here

1 个答案:

答案 0 :(得分:0)

最简单,最好的方法是使用一个名为jQuery的库。它允许您编写更少的代码,并为您提供大量预先编写的功能。

首先,在您的HTML文件<head>的{​​{1}}或底部包含jQuery:

<body>

接下来,您将要使用此JavaScript。确保它低于jQuery的<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.0.min.js"></script> 标记,否则它无法正常工作:

<script>

您也可以随时运行$(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); }); 内的特定代码,例如单击按钮等时。只要页面准备就绪,上面的特定代码就会立即运行。