如何使用Java脚本隐藏div? [英] how to hide div using java script ?

查看:85
本文介绍了如何使用Java脚本隐藏div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Java脚本plz隐藏div时遇到问题,请帮助我,我的示例代码为

i have a problem to hide div using java script plz help me my ssample code is as

<script type ="text/javascript" language ="javascript" >
function hideDiv()
{
var divs = document.getElementById ("treelist");
//divs.disabled =false ;
//divs.visible=true;
divs .setAttribute ('visible','true' );

}
</script>



和div为



and div is as

<div id= "treelist" visible ="false"  runat ="server"  >
        <asp:TreeView ID="tvDept" runat="server" BorderStyle="Solid" Width="156px"

          >
            <Nodes>
                <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node">
                    <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
                </asp:TreeNode>
                <asp:TreeNode Text="New Node" Value="New Node"></asp:TreeNode>
            </Nodes>
        </asp:TreeView>
    </div>

推荐答案

yogeshptl写道:
yogeshptl wrote:



您在此处使用了可见"属性.如果您使用它并将其设置为false,那么它将不再存在于页面中,因此Javascript将无法找到它.

而是使用显示"属性.



You used an attribute ''visible'' here. If you use that and set it to false then it would not be present in the page anymore and thus Javascript wont be able to find it.

Instead use ''display'' attribute.

<div style="display:none">



这将使控件保持在页面上并可以使用Javascript访问.

要切换显示值,请尝试:



This will keep the control on page and accessible in Javascript.

For toggling the value of display try:

var divs = document.getElementById ("treelist");
// to show
divs.style.display = "block";
// to hide
divs.style.display = "none";


这篇关于如何使用Java脚本隐藏div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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