hover()光标移入时触发第一个函数,光标移出时触发第二个函数
toggle()第一次单击触发第一个函数,在次单击触发第二个函数
例:
<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(){
//hover合成事件,光标移入时触发第一个函数,光标移出时触发第二个函数
//toggle合成事件,第一次单击触发第一个函数,再次单击触发第二个函数
/*$(".head").hover(function(){
$("div.content").hide();
},function(){
$("div.content").show();
});*/
//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>