Weitere ähnliche Inhalte
Ähnlich wie jQuery实践经验与技巧 (20)
jQuery实践经验与技巧
- 3. 成员 { 0: HTMLElement, 1: HTMLElement, 2: HTMLElement, …… length: 12, add:function(){}, addClass:function(){}, after: function(){}, …… }
- 11. 事件处理 bind(), unbind(), one(), trigger(), triggerHandler() $(‘#btn’).unbind(‘click’).bind(‘click’, {a: 1}, function(e){ console.log(e.data.a); }).bind({ focus: function(){}, blur: function(){} }).one(‘mouseover’, function(){}); $().bind(‘click’, function(){}) 等同$().click(function(){}) $().bind(‘focus’, function(){})等同$().focus(function(){}) …… 1、bind方法可以绑定自定义事件 2、可以向事件处理函数传递参数 3、更加灵活
- 17. 事件委派 live(type, fn), die(type) 给所有当前以及将来会匹配的元素绑定一个事件处理函数(比如click事件)。 也能绑定自定义事件。 <ul> <li></li> <li></li> <li></li> …… </ul> 插入 <li></li> $(‘li’).live(‘click’, function(){}); $(‘li’).die(‘click’);
- 18. AJAX事件 ajaxStart(), ajaxSend(), ajaxErorr(), ajaxSuccess(), ajaxStop(), ajaxComplete() $(‘#msg’).ajaxSend(function(){ $(this).html(‘sending…’); }).ajaxComplete(function(){ $(this).html(‘complete!’) }); $(‘#msg’).bind(‘ajaxSend’, function(){ $(this).html(‘sending…’); })