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

标签 javascript html css

如何在加载时设置高度和可见性 (detailsVisible)?提前致谢。

从这里开始:

from here

到这里:

to here

最佳答案

做到这一点的最简单、最好的方法是使用一个名为 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/

相关文章:

javascript - css 样式到 jquery - 不止一个属性

css - HTML5/CSS - <ol> 带有字母和括号?

javascript - 选择一组三个 li 并将它们显示在下一个或上一个按钮上

javascript - 使用 JavaScript API 的 Tableau 全屏 View

javascript - 从参数函数中获取值

html - 确保 div 与页面底部的距离

HTML 电子邮件 <hr/> 样式问题

javascript - LiveCycle Javascript 函数引用错误

html - 删除 html 中 img 标签后的换行符

html - 如何使用 css 网格正确制作页面布局?