jQuery之事件绑定&合成事件
2015-12-09 13:26
656 查看
jQuery之事件绑定&合成事件
示例代码:/jQuery01/WebRoot/event/e1.html
toggle(fn1,fn2...) -- 模拟鼠标连续单击事件
示例代码:/jQuery01/WebRoot/event/e2.html
1.事件绑定
bind(type,fn)2.绑定方式的简写形式
click(function(){});示例代码:/jQuery01/WebRoot/event/e1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>事件绑定</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="../js/jquery-1.11.1.js"></script> <script type="text/javascript"> $(function(){ /* //事件绑定正式写法 $('#d1').bind('click',function(){ $(this).html('hello java'); }); */ //事件绑定简写形式 $('#d1').click(function(){ $(this).html('hello java'); }); }); </script> </head> <body> <div id="d1">hello jQuery</div> </body> </html>
3.合成事件
hover(enter,leave) -- 模拟光标悬停事件toggle(fn1,fn2...) -- 模拟鼠标连续单击事件
示例代码:/jQuery01/WebRoot/event/e2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>合成事件</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="../js/jquery-1.11.1.js"></script> <style type="text/css"> .s1{ width:100px; height:100px; background-color:red; } .s2{ background-color:yellow; } </style> <script type="text/javascript"> $(function(){ /* //鼠标进入事件 $('.s1').mouseenter(function(){ $(this).addClass('s2'); }); //鼠标移除事件 $('.s1').mouseleave(function(){ $(this).removeClass('s2'); }); */ /* //合成事件--hover(enter,leave):模拟光标悬停事件 $('.s1').hover(function(){ $(this).addClass('s2'); },function(){ $(this).removeClass('s2'); }); */ //toggle(fn1,fn2...)--模拟鼠标连续单击事件 //实验结果不理想 $('a').toggle(function(){ $('#d1').show('slow'); },function(){ $('#d1').hide(); }); }); </script> </head> <body> <div class="s1">hello jQuery</div> <a href="javascript:;">显示所有票价</a> <div id="d1" style="display:none;"> 111<br/> 222<br/> 333<br/> 444<br/> </div> </body> </html>
相关文章推荐
- JS、Jquery获取浏览器和屏幕各种高度宽度
- 利用jQuery实现鼠标滑过整行变色
- jQuery中serializeArray()与serialize()的区别实例分析
- jQuery实现form表单元素序列化为json对象的方法
- jQuery实现页面顶部显示的进度条效果完整实例
- jquery内容的展开与折叠
- 【锋利的jQuery阅读笔记】jQuery中的DOM事件
- 【锋利的jQuery阅读笔记】jQuery选择器
- jQuery EasyUI使用教程之在数据网格中添加一个分页
- 【锋利的jQuery阅读笔记】认识jQuery
- jQuery中的.height()、.innerHeight()和.outerHeight()的区别
- jquery的ajax全局事件详解
- jquery.form.js笔记
- Jquery easyui从零单排之datagrid分页
- JQuery实现页面Loading效果
- jQuery Validate
- 给jquery easy-ui 添加右键菜单
- Struts2和Jquery整合使用异步请求
- jQuery easyui treegrid无法传参到后台bugger一记
- jquery插件ajaxupload实现文件上传操作