JQuery DIV 動態(tài)隱藏和顯示的方法
1. 如果在載入是隱藏:
<head>
<script language="javascript">
function HideWeekMonth()
{
$("#tt1").hide();
$("#tt2").hide();
}
</script>
</head>
<body onLoad="HideWeekMonth()">
</body>
2. 動態(tài)隱藏和顯示:
<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()切換元素的可見狀態(tài)。如果元素是可見的,切換為隱藏的;如果元素是隱藏的,切換為可見的。
$("#id").css('display','none');
$("#id").css('display','block');
或
$("#id")[0].style.display = 'none';
PS:下面給大家介紹jquery顯示隱藏div標簽的幾種方法
1、$("#demo").attr("style","display:none;");//隱藏div
$("#demo").attr("style","display:block;");//顯示div
2、$("#demo").css("display","none");//隱藏div
$("#demo").css("display","block");//顯示div
3、$("#demo").hide();//隱藏div
$("#demo").show();//顯示div
4、$("#demo").toggle(
function () {
$(this).attr("style","display:none;");//隱藏div
},
function () {
$(this).attr("style","display:block;");//顯示div
}
);
<div id="demo"></div>
相關(guān)文章
jquery1.4 教程一 便利的設(shè)置函數(shù)
jquery1.4已經(jīng)發(fā)布了,1.4相對于1.32的改進還是非常巨大的,可以說是全面性的,性能也全面超越了1.32。這一周,將一一展示jquery1.4的改進,同時也會放出相應的demo。2010-02-02
jQuery將多條數(shù)據(jù)插入模態(tài)框的示例代碼
這篇文章主要介紹了使用jQuery將多條數(shù)據(jù)插入模態(tài)框的方法,很簡單,很實用,需要的朋友可以參考下2014-09-09
使用Jquery來實現(xiàn)可以輸入值的下拉選單 雛型
最近案子中,需要使用下拉選單,但問題是,里面選項都會有各 其他:,然後 可以 讓 user 在輸入2011-12-12

