JQuery动态隐藏和显示DIV

1. 如果在载入是隐藏:

复制代码
<head>
<script language="javascript">
function HideWeekMonth()
{
    $("#tt1").hide();
    $("#tt2").hide();
}
</script>
</head>

<body onLoad="HideWeekMonth()">
</body>
复制代码

2. 动态隐藏和显示:

复制代码
            <td>
                <!-- 能用
                <input id="btnShow" type="button" value="<?php echo $ini_array['module.insert'];?>" class="btn" />
                <input id="btnHide" type="button" value="<?php echo $ini_array['module.insert'];?>" class="btn" /> 
                -->
                <!-- 直接使用按钮的id没有问题
                <input id="tt" type="text" name="title" maxlength="50" size="50"></td> -->
                <input id="btnOne" type="radio" name="frequence" value="1" checked='checked'><?php echo $ini_array['time.one']?>&nbsp;&nbsp;&nbsp;&nbsp;
                <input id="btnDay" type="radio" name="frequence" value="2"><?php echo $ini_array['time.day']?>&nbsp;&nbsp;&nbsp;&nbsp;
                <input id="btnWeek" type="radio" name="frequence" value="3"><?php echo $ini_array['time.week']?>&nbsp;&nbsp;&nbsp;&nbsp;
                <input id="btnMonth" type="radio" name="frequence" value="4"><?php echo $ini_array['time.month']?>&nbsp;&nbsp;&nbsp;&nbsp;
                <br>
                <!-- 能用
                <div id="tt1"><input type="text" name="title" maxlength="50" size="50" value="tt1"></div>
                <div id="tt2"><input type="text" name="title" maxlength="50" size="50" value="tt2"></div> 
                -->
                <div id="tt1">                
                    <br>
                    1&nbsp;<input type="checkbox" value="1" name="w1">&nbsp;&nbsp;&nbsp;&nbsp;
                    2&nbsp;<input type="checkbox" value="1" name="w2">&nbsp;&nbsp;&nbsp;&nbsp;</div>
                <div id="tt2">                
03&nbsp;<input type="checkbox" name="m3">&nbsp;&nbsp;&nbsp;&nbsp;
                    04&nbsp;<input type="checkbox" name="m4">&nbsp;&nbsp;&nbsp;&nbsp;</div>
          </td>

    <!-- 绑定事件似乎要写在被绑定对象的后面 -->
    <script type="text/javascript" >
        $("#btnOne").bind("click", function(event) { $("#tt1").hide(); $("#tt2").hide(); });
        $("#btnDay").bind("click", function(event) { $("#tt1").hide(); $("#tt2").hide(); });
        $("#btnWeek").bind("click", function(event) { $("#tt1").show(); $("#tt2").hide(); });
        $("#btnMonth").bind("click", function(event) { $("#tt1").hide(); $("#tt2").show(); });
    </script>
复制代码

以上代码之前,可能还要加上这句话:

<script type="text/javascript" src="../../scripts/jquery.min.js"></script>

 

使用jquery真的很方便,比如要控制div的显示与隐藏,一句话就搞定了,请看下面使用说明。
$("#id").show()表示display:block, 
$("#id").hide()表示display:none; 
$("#id").toggle()切换元素的可见状态。如果元素是可见的,切换为隐藏的;如果元素是隐藏的,切换为可见的。

$("#id").css('display','none'); 
$("#id").css('display','block'); 
或 
$("#id")[0].style.display = 'none';

转载于:https://www.cnblogs.com/shin6758/p/6058240.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值