1:hover() 用于模拟光标悬停事件,hover(enter,leave),当光标移动到元素上时会触发第一个函数enter,当光标移除元素时触发第二个函数enter。
|
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="/TestJquery/jq/jquery-1.3.2.js"></script>
<title>Insert title here</title>
<style type="text/css">
.head{
color:red;
font-size:30px;
font-weight:bold;
background-color: yellow;
}
.content{
display: none;
}
</style>
</head>
<body>
<div id="panel">
<h5 class="head">什么事Jquery</h5>
<div class="content">
jaueryshi是一个优秀的javascript库.....
</div>
</div>
</body>
<script type="text/javascript">
$(function(){
$("#panel h5.head").hover(function(){
$(this).next("div.content").show();
},function(){
$(this).next("div.content").hide();
});
});
</script>
</html>
*(以上的hover函数写法其实等价于鼠标获取焦点和取消焦点事件,如果想把这种效果改成鼠标点击展现的话把mouseover和mouseout事件换成click就OK了。) |
$(function(){
$("#panel h5.head").bind("mouseover",function(){
$(this).next("div.content").show();
});
$("#panel h5.head").bind("mouseout",function(){
$(this).next("div.content").hide();
});
});
2:toggle() 用于模拟鼠标连续单击事件。toggle(f1,f2,.....),第一次单击时触发第一个函数f1,第二次单击时触发第二个函数f2以此类推直到最后一个。随后的每次单击事件循环这一过程。
|
$(function(){
$("#panel h5.head").toggle(function(){
$(this).next("div.content").show();
},function(){
$(this).next("div.content").hide();
});
});
*(toggle()还有另外一个作用就是切换元素的可见状态。上面的代码等同于)
|
$(function(){
$("#panel h5.head").toggle(function(){
$(this).next("div.content").toggle();
},function(){
$(this).next("div.content").toggle();
});
});
本文出自 “小浩” 博客,请务必保留此出处http://zhangchi.blog.51cto.com/5214280/1221646