1、toggle jquery Dom中切换样式
2、toggle 事件,点击触发一个函数,在点击触发另一个函数
3、toggle jquery动画切换
1、例:
<script type="text/javascript" src="../script/jquery-1.4.2.min.js"></script>
<title>无标题文档</title>
</head>
<style>
.high{font-style:italic;
font-weight:bold;}
.hide{
display:none;}
</style>
//toggleClass()切换样式,如果你有这个class属性我就删除,如果没有就增加
$("p").toggleClass("hide");
})
</script>
<body>
<p class = "hight1"title="水果">你最喜欢的水果</p>
<ul>
<li>苹果</li>
<li name="o">橘子</li>
<li name="m">香蕉`</li>
</ul>
</body>
2、例:
<meta charset="utf-8"/>
<style>
*{ margin:0; padding:0;}
body{font-size:15px;}
#container{ margin:60px; line-height:2em; width:300px; border:1px solid #CCC;}
.head{ background:#999; padding:5px; cursor:pointer;}
.content{ text-indent:15px;}
</style>
<script type="text/javascript" src="../script/jquery-1.4.2.min.js"></script>
<script>
$(function(){
//toggle合成事件,第一次单击触发第一个函数,再次单击触发第二个函数
$("h5.head").toggle(function(){
$("div.content").hide();
},function(){
$("div.content").show();
});
})
</script>
</head>
<body>
<div id="container">
<h5 class="head">什么是jQuery?</h5>
<div class="content">
JQuery是继prototype原型之后又一个javascript库,他凭借简单的代码和完善的浏览器兼容性,再加上强大的DOM操作,完善的事件处理机制,强大的ajax操作,加大的简化了javascript开发人员的工作。
</div>
</div>
</body>
3、例:
<style>
*{ margin:0; padding:0;}
body{font-size:15px;}
#container{ margin:60px; line-height:2em; width:300px; border:1px solid #CCC;}
.head{ background:#999; padding:5px; cursor:pointer;}
.content{ text-indent:15px;}
</style>
<script type="text/javascript" src="../script/jquery-1.4.2.min.js"></script>
<script>
//切换动画效果,有就显示没有就隐藏
$(function(){
$("h5.head").click(function(){
$("div.content").toggle();
//$("div.content").toggle(5000);
});
})
</script>
</head>
<body>
<div id="container">
<h5 class="head">什么是jQuery?</h5>
<div class="content">
JQuery是继prototype原型之后又一个javascript库,他凭借简单的代码和完善的浏览器兼容性,再加上强大的DOM操作,完善的事件处理机制,强大的ajax操作,加大的简化了javascript开发人员的工作。
</div>
</div>
</body>