大佬教程收集整理的这篇文章主要介绍了jQuery绑定事件侦听器之前的另一个,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
麻烦是,当我
$('a.videoClickListener').click(function(event){ console.log('here'); _gaq.push(['_trackEvent','Product Page','Video Open','<?PHP echo $product->getNameWithManufacturer(); ?>']); });
事件永远不会被触发,因为prettyPhoto阻止事件继续(非常正确地,否则如果点击超链接,页面会改变).
prettyPhoto似乎并没有提供一个’开放’回调函数,但是如果我无法使用它,因为prettyPhoto监听器设置在布局的某个地方(我们每次要使用rel =“prettyPhoto”) prettyPhoto,并通过URL传递参数,这是prettyPhoto推荐的做事方式).我也想将产品细节传递给Google Analytics(分析),排除了所有prettyPhoto开幕活动中的全球视频开放听众.
如何在prettyPhoto侦听器之前绑定我的监听器?如果事实证明,我必须使用.unbind(),然后绑定我的监听器,然后重新绑定prettyPhoto,我如何解除绑定在插件中指定的处理程序?
不幸的是,jQuery似乎没有包含任何这样的设施.
不过,我已经编写了一个preBind method,这似乎是诀窍:
$.fn.preBind = function(type,data,fn) { this.bind(type,fn); var currentBindings = this.data('events')[type]; var currentBindingsLasTindex = currentBindings.length - 1; var newBindings = []; newBindings.push(currentBindings[currentBindingsLasTindex]); $.each(currentBindings,function (indeX) { if (index < currentBindingsLasTindeX) newBindings.push(this); }); this.data('events')[type] = newBindings; return this; };
用法:
$('#button').bind('click',function() { console.log('world'); }); // 2nd apostrophe for the SELEctor was missing $('#button').preBind('click',function() { console.log('Hello'); }); $('#button').click(); // Output: // // > "Hello" // > "world"
以上是大佬教程为你收集整理的jQuery绑定事件侦听器之前的另一个全部内容,希望文章能够帮你解决jQuery绑定事件侦听器之前的另一个所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。