JQuery顯示隱藏DIV的方法及代碼執行個體,jquerydiv代碼執行個體

來源:互聯網
上載者:User

JQuery顯示隱藏DIV的方法及代碼執行個體,jquerydiv代碼執行個體

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']?>    
                <input id="btnDay" type="radio" name="frequence" value="2"><?php echo $ini_array['time.day']?>    
                <input id="btnWeek" type="radio" name="frequence" value="3"><?php echo $ini_array['time.week']?>    
                <input id="btnMonth" type="radio" name="frequence" value="4"><?php echo $ini_array['time.month']?>    
                <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 <input type="checkbox" value="1" name="w1">    
                    2 <input type="checkbox" value="1" name="w2">    </div>
                <div id="tt2">               
03 <input type="checkbox" name="m3">    
                    04 <input type="checkbox" name="m4">    </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';

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.