如何隐藏或显示一个div [英] How to hide or show a div

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

问题描述

我有我的Page_Load注册了这个

I have on my Page_Load registered this

 Page.ClientScript.RegisterStartupScript(this.GetType(), "clientscript", "document.getElementById('showdiv').style.visibility = 'hidden';", true);

但它没有得到隐藏的...我的div是如下图所示。

But its not getting hidden... My div is as shown below

<div id="showdiv">
   <input class="button" type="button" value="OK" name="success_button" id="my button"  onclick="javascript:window.close();" />
   </div>

我在做什么错了?感谢您的帮助。

what am I doing wrong?. Thank you for your help

推荐答案

我强烈建议使用JavaScript和像jQuery的.js库做这个简单的客户端操作(显示/ HODE行控制等),甚至更容易。当您在您的应用程序jQuery的脚本,这是所有你需要做的,在页面完成初始化后DIV隐藏。

I highly recommend doing this simple client side manipulation (show/hode rows controls, etc.) with JavaScript or even more easily with a .js library like jQuery. After you include the jQuery scripts in your application, this is all you need to do to have that DIV be hidden after the page has completed its initialization.

包含在您的页面或引用的.js顶这个脚本文件部分,如果你已经有一个:

Include this script section at the top of your page or in a referenced .js file if you already have one:

<script type="text/javascript">

 //$(document).ready is used to define a function that is guaranteed to be called only after the DOM has been initialized.
 $(document).ready(function () {
    //Hide the div
    $('#showdiv').hide();
    //conversely do the following to show it again if needed later
    //$('#showdiv').show();
 });

</script>

这种方法

jQuery的API文档:结果
http://api.jquery.com/hide/

这篇关于如何隐藏或显示一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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