显示/隐藏div,使用普通JS [英] Show/Hide div, with plain JS

查看:71
本文介绍了显示/隐藏div,使用普通JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CSS:

#a_x200{
    visibility: hidden;
    width: 200px;
    height: 200px;
    background-color: black;
}

我的JS:

<script type="text/javascript">
    function show(id) {
        document.getElementById(id).style.display = 'block';
    }
</script>

我的HTML

<div id="a_x200">asd</div>
<innput type="button" class="button_p_1" onclick="show('a_x200');"></input>

不工作,我想我错过了一些东西!

Not working I think I missed something!

推荐答案

您正在使用visibility: hidden隐藏它,然后尝试使用display CSS属性使其可见.它们是两个完全独立的属性,更改一个不会神奇地更改另一个.

You're using visibility: hidden to hide it, then attempting to use the display CSS property to make it visible. They're two completely separate properties, changing one won't magically change the other.

如果要使其再次可见,请将visibility属性的值更改为visible:

If you want to make it visible again, change the value of the visibility property to visible:

document.getElementById('a_x200').style.visibility = 'visible';

这篇关于显示/隐藏div,使用普通JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆