JQuery中的事件 (八.其他用法)
来源:互联网 发布:淘宝店主风调色滤镜 编辑:程序博客网 时间:2024/05/21 08:00
1.绑定多个事件类型bind("mouseover mouseout",...)
<style> div{width:100px;height:50px; } .over{ color:red; background:#888; } </style> <script type="text/javascript"> $(function(){ $("div").bind("mouseover mouseout", function(){ $(this).toggleClass("over"); }); }) </script></head><body><div >滑入.</div></body>
2.添加时间命名空间,便于管理
<style>div{width:100px;height:50px;background:#888;color:white;} </style> <script type="text/javascript"> $(function(){$("div").bind("click.plugin",function(){ $("body").append("<p>click事件</p>");});$("div").bind("mouseover.plugin", function(){ $("body").append("<p>mouseover事件</p>");});$("div").bind("dblclick", function(){ $("body").append("<p>dblclick事件</p>");});$("button").click(function() {$("div").unbind(".plugin"); })/*click,mouseover 事件被删除,*/ }) </script></head><body><div>test.</div><button >根据命名空间,删除事件</button></body>
3.相同事件名称,不同命名空间执行方法,!执行除去命名空间的点击事件
<style>div{width:100px;height:50px;background:#888;color:white;} </style> <script type="text/javascript"> $(function(){$("div").bind("click",function(){ $("body").append("<p>click事件</p>");});$("div").bind("click.plugin", function(){ $("body").append("<p>click.plugin事件</p>");});$("button").click(function() { $("div").trigger("click!"); // 注意click后面的感叹号}); }) </script></head><body><div >test.</div><button >根据命名空间,触发事件</button></body>
1 0
- JQuery中的事件 (八.其他用法)
- 4.1.8: jQuery事件之其他用法
- jQuery-jQuery中的事件
- jquery load 事件用法
- jquery load 事件用法
- jquery load 事件用法
- jquery load 事件用法
- jquery load 事件用法
- jquery load 事件用法
- jQuery学习笔记之八----基础事件
- 【jQuery】jQuery中的事件处理
- jQuery中的事件
- jQuery中的事件总结
- jQuery 中的事件绑定
- jQuery中的事件总结
- jQuery 中的事件
- jQuery中的事件处理
- jquery中的事件
- 【测试】软件测试的艺术读书笔记
- java集合
- 直通BAT算法面试题总结
- tableView左滑 编辑 删除或其他操作
- java 手写动态代理
- JQuery中的事件 (八.其他用法)
- VM下 虚拟机和主机能互相ping通,但主机不能访问虚拟机中的服务
- Retrofit用法详解
- 回答阿里社招面试如何准备,顺便谈谈对于Java程序猿学习当中各个阶段的建议
- Mybatis -- Mybatis-Generator自动生成Dao、Model、Mapping文件及其使用
- LoadRunner 和 HTTP 401 验证
- Chorm Console 查看Ajax Request
- spark自定义Accumulator高级应用(JAVA)
- RTMP协议从入门到放弃