博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JQuery 事件
阅读量:4701 次
发布时间:2019-06-09

本文共 1632 字,大约阅读时间需要 5 分钟。

常用事件

			
事件目标和冒泡
  • A
  • B
  • C
  • D

  

 

自定义事件:

我的理解,就是将某元素的行为进行封装,  这样将事件的触发与行为进行解耦

参考代码:

			
trigger demo /*An example is probably the best way to explain. Suppose you have a lightbulb * in a room in a house. The lightbulb is currently turned on, and it's controlled by two three-way switches and a clapper: Triggering the clapper or either of the switches will change the state of the lightbulb. The switches and the clapper don't care what state the lightbulb is in; they just want to change the state If there are any lights on in the house, we want the master switch to turn all the lights off; otherwise, we want it to turn all lights on*/
房子1
开关1
开关2
房子2
开关1
开关2
总开关

  

注意事项:

1. 相同事件添加到父节点即可,通过target来获取当前点击的元素

$('#myTable').click(function(e) {var $clicked = $(e.target);$clicked.css('background', 'red'); });

  

2. 别把过多代码绑定到document.ready中,可以把部分不需要的移入windows.load中

以下是引用片段:

$(window).load(function(){// 页面完全载入后才初始化的jQuery函数.});

  

3.可以用data(),存储临时变量

以下是引用片段:

$(function(){   $("button").click(function(){     if( $("p").data("flag") ){     $("p").text("true");     $("p").data("flag",false);   }else{     $("p").text("false");     $("p").data("flag",true);  }});})

  

转载于:https://www.cnblogs.com/yqlog/p/5572532.html

你可能感兴趣的文章
CHD-5.3.6集群上sqoop安装
查看>>
解决无/var/log/messages 问题
查看>>
ThinkPHP5.0中Request请求对象的常用操作
查看>>
js 判断是不是空、值是否存在
查看>>
windows 启动关闭Oracle监听和服务 (转载)
查看>>
【小程序云开发入门】quickStart
查看>>
分布式一致性协议-2PC与3PC(二)
查看>>
em与当前元素的不解之缘
查看>>
学号 《信息安全系统设计基础》第6周学习总结(一)
查看>>
alpha阶段个人总结
查看>>
不透明度opacity进阶
查看>>
C++代码中回调JS方法
查看>>
(WPF) MVVM: 动态添加控件及绑定。
查看>>
SQL中的charindex()方法
查看>>
地图坐标相关计算
查看>>
我一定会成功的!
查看>>
INFORMATICA 的调优之一 源数据的优化
查看>>
MyEclipse中配置tomcat
查看>>
C# 实现对接电信交费易自动缴费
查看>>
斐波那契数列-兔子问题
查看>>