Home > Article > Web Front-end > How jquery handles events
Jquery's method of handling events: 1. Unregister the event handler, the code is [$('*').unbind();]; 2. Trigger the event [trigger();]; 3. Customize Event, the code is [$('div').click(function(){$.event.trigg].
The operating environment of this tutorial: windows7 system , jquery3.2.1 version, Dell G3 computer.
Recommendation: jquery video tutorial
##jquery event processing method:
Simple registration of event handlers
//单击任意div时,使其背景变成黄色 $('div').click(function(){ $(this).css({backgroundColor:'yellow'}); }); //toggle(), 将多个事件处理程序函数绑定到单击事件, 按顺序一次调用一个函数; $('div').toggle(function(){this.innerText='0'},function(){this.innerText='1'},function(){this.innerText='2'},); //hover(), 用来给mouseenter 和 mouseleave事件注册事件处理函数 第一个参数是mouseenterHandler , 第二个参数是mouseleaveHandler, 如果mouseenterHandler 与mouseleaveHandler相同, 可以合并,只学一个Handler函数
Advanced registration of event handlers
bind();// 最简单的使用bind方法 $('div').bind('click','牛逼的bind()',function(event){this.innerText = event.data});
Unbind event handler
unbind()$(’*’).unbind() ; //从所有元素中移除所有的jQuery事件处理程序
Trigger event
##trigger();//用户单击div , 广播一个自定义事件what事件;
$('div').bind('what',function(event){console.log(event.type)});
$('div').click(function(){$.event.trigger('what')});
##delegate();
undelegate();
##Related learning recommendations:
The above is the detailed content of How jquery handles events. For more information, please follow other related articles on the PHP Chinese website!