JQuery動態隱藏和顯示DIV

JQuery動態隱藏和顯示DIV

1. 若是在載入是隱藏:javascript

複製代碼

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

<body onLoad="HideWeekMonth()">
</body>

複製代碼

2. 動態隱藏和顯示:php

複製代碼

<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>

複製代碼

以上代碼以前,可能還要加上這句話:css

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

 

使用jquery真的很方便,好比要控制div的顯示與隱藏,一句話就搞定了,請看下面使用說明。
$("#id").show()表示display:block, 
$("#id").hide()表示display:none; 
$("#id").toggle()切換元素的可見狀態。若是元素是可見的,切換爲隱藏的;若是元素是隱藏的,切換爲可見的。
java

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

分類: Web-JQueryide

相關文章
相關標籤/搜索