<!doctype html>

<html lang="us">

<head>

<meta charset="utf-8">

<title> test</title>

<script src="./jquery-1.10.2.js" type="text/javascript"></script>

<script>

function initEvents(){

//注冊多次事件方法初始化

initOnEvent();

initBindEvent();

initClickvent();

initLiveEvent();

//仅仅注冊一个事件方法

oneEventByBindUnBind();

oneEvnetByDieLive();

}

function initOnEvent(){

//为id为onWayToEvent button注冊点击事件

$("#onWayToEvent").on("click",function(){

alert("this is one on event")

});

$("#onWayToEvent").on("click",function(){

alert("this is two on event")

});

$("#onWayToEvent").on("click",function(){

alert("this is three on event")

});

}



function initBindEvent(){

//为id为bindWayToEvent 的button注冊点击事件

$("#bindWayToEvent").bind("click",function(){

alert("this is registry event by bind. one")

});



$("#bindWayToEvent").bind("click",function(){

alert("this is registry event by bind. two")

});



$("#bindWayToEvent").bind("click",function(){

alert("this is registry event by bind. three")

});

}



function initClickvent(){

$("#clickWayToEvent").click(function(){

alert("this is registry event by click. one");

});



$("#clickWayToEvent").click(function(){

alert("this is registry event by click. two");

});

$("#clickWayToEvent").click(function(){

alert("this is registry event by click. three");

});

}



function initLiveEvent(){

$("#liveWayToEvent").live("click",function(){

alert("this is registry event by click. one");

});

/*

$("#clickWayToEvent").click(function(){

alert("this is registry event by click. two");

});

$("#clickWayToEvent").click(function(){

alert("this is registry event by click. three");

});

*/

}





function oneEventByBindUnBind(){

 

registryManyEvent("oneEvnetByBind");

$("#oneEvnetByBind").unbind("click").bind("click",function(){

alert("only you !!!!!!!");

});



}



function oneEvnetByDieLive(){

registryManyEvent("oneEvnetByDieLive");

$("#oneEvnetByDieLive").die().live("click",function(){



alert("the one of you !!!!!!");

});

}



function registryManyEvent(id){

$("#"+id).click(function(){

alert("this is registry event by common. one");

});



$("#"+id).click(function(){

alert("this is registry event by common. two");

});

$("#"+id).click(function(){

alert("this is registry event by common. three");

});

}



</script>

<style>

 

.info{

width:100%;

height:auto;

float:auto;

margin:10px;


}

 

</style>

 

</head>

<body onload="initEvents()">





<h1>Welcome to jquery registry event test</h1>

<button id="onWayToEvent" >通过on的方式多次注冊事件</button>  </br>

<div class="info">

通过 on方法注冊的事件,每次的注冊不会把原来的方法覆盖掉。

会以队列的形式保存起来

点击的时候,触发事情会一个个按注冊的顺序运行。

主要代码:

function initOnEvent(){

//为id为onWayToEvent button注冊点击事件

$("#onWayToEvent").on("click",function(){

alert("this is one on event")

});

$("#onWayToEvent").on("click",function(){

alert("this is two on event")

});

$("#onWayToEvent").on("click",function(){

alert("this is three on event")

});

}



</div>

<button id="bindWayToEvent">通过bind的方法多次注冊事件</button>



<div class="info" >

通过 jquery 的bind方法多次注冊的方法也是一样,不会把原来的方法覆盖了,也是把方法以

队列的形式保存起来。触发事件后按注冊次序逐个运行。



主要代码:

function initBindEvent(){

//为id为bindWayToEvent 的button注冊点击事件

$("#bindWayToEvent").bind("click",function(){

alert("this is registry event by bind. one")

});



$("#bindWayToEvent").bind("click",function(){

alert("this is registry event by bind. two")

});



$("#bindWayToEvent").bind("click",function(){

alert("this is registry event by bind. three")

});

}

</div>



<button id="clickWayToEvent">通过click方法多次注冊事件</button>

<div class="info" >

通过 jquery 的click方法多次注冊的方法也是上面的效果一样 。





主要代码:

function initClickvent(){

$("#clickWayToEvent").click(function(){

alert("this is registry event by click. one");

});



$("#clickWayToEvent").click(function(){

alert("this is registry event by click. two");

});

$("#clickWayToEvent").click(function(){

alert("this is registry event by click. three");

});

}

</div>

<button id="liveWayToEvent">通过live 方法多次注冊事件</button>

<div class="info" >

 要怎么样才干把前面的事件给覆盖掉。仅仅保留最后注冊的事件方法?

</div>



<button id="oneEvnetByBind">通过unbind,bind方法进行事件的唯一注冊</button>

<div class="info">

这种方法能够行得通

主要代码:

function oneEventByBindUnBind(){

 

registryManyEvent("oneEvnetByBind");

$("#oneEvnetByBind").unbind("click").bind("click",function(){

alert("only you !!!!!!!");

});



}



 



function registryManyEvent(id){

$("#"+id).click(function(){

alert("this is registry event by common. one");

});



$("#"+id).click(function(){

alert("this is registry event by common. two");

});

$("#"+id).click(function(){

alert("this is registry event by common. three");

});

}



</div>



<button id="oneEvnetByDieLive">通过 die live 方法进行事件的唯一载入</button>

<div class="info">

我们用的 jquery-1.10.2.js 这里没有提供 die live 方法。

对于网上提供的这种方法是无效的。

主要代码:

function oneEvnetByDieLive(){

registryManyEvent("oneEvnetByDieLive");

$("#oneEvnetByDieLive").die().live("click",function(){



alert("the one of you !!!!!!");

});

}



function registryManyEvent(id){

$("#"+id).click(function(){

alert("this is registry event by common. one");

});



$("#"+id).click(function(){

alert("this is registry event by common. two");

});

$("#"+id).click(function(){

alert("this is registry event by common. three");

});

}



</div>



</body>

</html>

jquery 事件注冊 与反复事件处理的更多相关文章

  1. struts2+jquery验证注冊用户是否存在

    注冊界面 register.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&q ...

  2. jquery 事件,注册 与重复事件处理

    jquery有时候会出现重复注册一个事件的问题,导致点击一个事件,这个事件被重复执行,也就是触发事件的次数有几次, 那么这个事件就会被执行叠加重复几次. 我这边做的一个项目,在某个页面初始化的时候,给 ...

  3. jquery事件手冊

    方法 描写叙述 bind() 向匹配元素附加一个或很多其它事件处理器 blur() 触发.或将函数绑定到指定元素的 blur 事件 change() 触发.或将函数绑定到指定元素的 change 事件 ...

  4. jquery注冊文本框获取焦点清空,失去焦点赋值

    在我们开发过程中特别是用户注冊时会有一个效果.就是文本框获取焦点清空提示,假设用户没有输入信息失去焦点赋值上我们的提示语 <html> <head> <meta http ...

  5. android点滴之标准SD卡状态变化事件广播接收者的注冊

    眼下最完整的,须要注冊的动作匹配例如以下: IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED); int ...

  6. Android实战简易教程-第二十三枪(基于Baas的用户注冊验证username是否反复功能!)

    接上一篇,加入验证用户名是否已经注冊功能! 仅仅须要改动MainActivity.java: package com.example.logintest; import java.util.List; ...

  7. 完美的jquery事件绑定方法on()

    在讲on()方法之前,我们先讲讲在on()方法出现前的那些事件绑定方法: .live() jQuery 1.3新增的live()方法,使用方法例如以下: $("#info_table td& ...

  8. jQuery事件传播,事件流

    一. jQuery事件传播 在DOM2级事件模型中,一旦事件被触发.事件流首先从DOM树顶部(文档节点)向下传播.直到目标节点.然后再从目标节点向上传播到DOM树顶.从上到下的过程被称为捕获阶段.从下 ...

  9. jQuery事件大全

    jQuery事件大全 attribute:  $(" p" ).addclass(css中定义的样式类型) 给某个元素添加样式 $(" img" ).attr( ...

随机推荐

  1. 转载|23个Python爬虫开源项目代码:爬取微信、淘宝、豆瓣、知乎、微博等

    地址:https://ask.julyedu.com/article/323

  2. Android应用开发学习笔记之Fragment

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz Fragment翻译成中文就是“碎片”.“片断”的意思,Fragment通常用来作为一个Activity用户界面的一 ...

  3. zookeeperclient代码解读

    近期一直在忙WebPageTest(下面简称wpt)开源库的改动工作,当中一项工作须要将zookeeper(下面简称zk)集成到wpt里. zk作为分布式系统的同步工具.实现了写的原子性(要么失败.要 ...

  4. Android开发之对话框高级应用

    Android开发之对话框高级应用 创建并显示一个对话框非常easy.可是假设想进行一些更高级点的操作,就须要一些技巧了.以下将和大家分享一下对话框使用的一些高级技巧. 1.改变对话框的显示位置: 大 ...

  5. CheeseZH: Stanford University: Machine Learning Ex4:Training Neural Network(Backpropagation Algorithm)

    1. Feedforward and cost function; 2.Regularized cost function: 3.Sigmoid gradient The gradient for t ...

  6. C语言变量的声明位置

    标准C里面必须放在代码前面,否则出错: C++里面不一定要放在最前面,用的时候声明也不迟: 所以要看具体的编译环境,如果是C的话必须放在最前,C++就不用:一般.c后缀的是C文件,按C来编译:.cpp ...

  7. Spring中依赖注入的四种方式

    在Spring容器中为一个bean配置依赖注入有三种方式: · 使用属性的setter方法注入  这是最常用的方式: · 使用构造器注入: · 使用Filed注入(用于注解方式). 使用属性的sett ...

  8. Oracle使用——PLSQL的中文乱码显示全是问号

    问题 这两天刚将PLSQL与Oracle配置好,但是在PLSQL中插入数据时.出现一个问题,PLSQL中的表里无法显示中文,中文无法保存.无法输出.中文在表中显示问号.如图: 原因 经过一番查证,发现 ...

  9. JVM内存管理、JVM垃圾回收机制、新生代、老年代以及永久代

    内存模型 JVM运行时数据区由程序计数器.堆.虚拟机栈.本地方法栈.方法区部分组成,结构图如下所示. JVM内存结构由程序计数器.堆.栈.本地方法栈.方法区等部分组成,结构图如下所示: 1)程序计数器 ...

  10. Jsp和session、request.getSession()

    request.getSession(false); 这段代码代表,如果没有和当前request关联的session则不创建session并且返回空 request.getSession(true); ...