所以我有一类 div,我想根据我得到的变量来显示或隐藏它。
我有这个代码:
**HTML**
<div class="div_estado" >
testing that
</div>
<div class="div_estado" >
testing this
</div>
**JS**
$(document).ready(function(){
var estado= 4; //instead of 4 i have "<?php echo $_GET['estado']; ?>" but let's supose its' value is 4
if (parseInt(estado)==5)
{
$('.div_estado').show; // not working
}
else {
$('.div_estado').hide; // not working
}
});
但是它无法正常工作,你能帮我解决这个问题吗?
最佳答案
hide
和 show
是方法,而不是属性。调用 JavaScript 函数的语法需要在函数名称后添加一组括号。
$('.div_estado').show();
$('.div_estado').hide();
关于javascript - 显示/隐藏 div 加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17466277/