jquery 合成事件

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值