温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jquery 合成事件

发布时间:2020-07-09 00:54:04 来源:网络 阅读:228 作者:小浩51 栏目:web开发

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">
    <h6 class="head">什么事Jquery</h6>
    <div class="content">
        jaueryshi是一个优秀的javascript库.....
    </div>
</div>
</body>
<script type="text/javascript">
$(function(){
    $("#panel h6.head").hover(function(){
        $(this).next("div.content").show();
    },function(){
        $(this).next("div.content").hide();
    });
});
</script>
</html>
*(以上的hover函数写法其实等价于鼠标获取焦点和取消焦点事件,如果想把这种效果改成鼠标点击展现的话把mouseover和mouseout事件换成click就OK了。)
$(function(){
    $("#panel h6.head").bind("mouseover",function(){
        $(this).next("div.content").show();
    });
$("#panel h6.head").bind("mouseout",function(){
        $(this).next("div.content").hide();
    });
});
2:toggle() 用于模拟鼠标连续单击事件。toggle(f1,f2,.....),第一次单击时触发第一个函数f1,第二次单击时触发第二个函数f2以此类推直到最后一个。随后的每次单击事件循环这一过程。  
$(function(){
    $("#panel h6.head").toggle(function(){
        $(this).next("div.content").show();
    },function(){
        $(this).next("div.content").hide();
    });
});
*(toggle()还有另外一个作用就是切换元素的可见状态。上面的代码等同于)
$(function(){
    $("#panel h6.head").toggle(function(){
        $(this).next("div.content").toggle();
    },function(){
        $(this).next("div.content").toggle();
    });
});


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI