要更改变量的高度li元素
Height li element to change variable
我想根据li元素的高度来更改值。元素是基于我们数据库中的一个值显示的,该值不能在此处使用。
这是我的HTML代码:
<li id="ul_customer1">
<a href="" ng-click="menu('pages/1.html')" id="menu-1" class="editable nav-label">Achtergronddata</a>
</li>
还有我的Javascript代码:
if($("ul_customer1").actual("height") > 5) {
var customer= 1;
} else {
var customer= 0;
}
激活时,li的高度=129。隐藏时为4。
我还尝试了"可见"answers"css显示块",但这些都不起作用。
如何根据li元素的高度更改var customer?
谢谢,
Isabelle
您可以使用outerHeight()
或height()
函数:
if ($("#ul_customer1").height() > 5) {
var customer = 1;
} else {
var customer = 0;
}
并确保为id
提供#
。
这里有一个演示给你:
当#ul_customer1
内部什么都没有时
$(function () {
if ($("#ul_customer1").height() > 5) {
var customer = 1;
} else {
var customer = 0;
}
alert(customer);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ul_customer1"></div>
当#ul_customer1
内部有东西时
$(function () {
if ($("#ul_customer1").height() > 5) {
var customer = 1;
} else {
var customer = 0;
}
alert(customer);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ul_customer1">Hello<br />Hi</div>
注意:这在我看来像是一个X-Y问题。我相信你正在检查特定元素是否为空。如果是这种情况,请改用
:is(empty)
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 单击页面上的链接后高度发生变化
- 使用CSS或js,使用动态选择器选择任意li的下一个元素
- 引导程序:在导航栏中,显示悬停在单个位置的基于Li Link的不同内容
- 不加载宽度和高度的角度pintura
- 更改li标记文本的Javascript
- 查找元素高度,包括边距
- 完全可链接的li元素
- 如何自动调整标签的高度以适应内容
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- 使用jquery动态创建ul-li
- 要更改变量的高度li元素
- 使用 jQuery 获取 LI 的高度,以便新闻自动收报机向上滚动所需的确切数量
- 改变li高度会移动父高度
- li高度的动态计算
- 为什么CSS break(不取li的高度)