jQuery如何设置绑定顺序 [英] jQuery how to set a Binding Order

查看:134
本文介绍了jQuery如何设置绑定顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以设置优先级绑定?

is there a way to set a binding over, precedence?

我有这样的链接:

<a href="" class="popItUp" data-track"stuff"> </a>

popItUp绑定以获取URL并在弹出窗口中打开.

popItUp binds to take the url and open in a popup.

data-track是另一个用于发送事件跟踪数据的绑定.

data-track is another binding that is used to send event tracking data.

问题: popItUp返回false,并且永远不会触发数据轨道绑定.有没有办法让数据跟踪始终由jQuery首先运行,因为它将始终返回true?

Problem: popItUp returns false, and the data-track binding is never fired. Is there a way to always make data-track run first by jQuery as it will always return true?

谢谢

代码

// Mixpanel Click Tracking
$('[data-track]').live('click', function () {
    console.log('track it please');
});

$('.popItUp').popupWindow({height:300,width:600,centerBrowser:1});

popUpWindow是一个插件: http://swip.codylindley.com/popupWindowDemo.html

popUpWindow is a plugin: http://swip.codylindley.com/popupWindowDemo.html

推荐答案

如果首先绑定了popItUp处理函数,并且如果绑定了returns false,则不会调用data-track binding.如果您想赋予它更高的优先级,而又与popItUp的作用无关,则需要首先绑定data-track binding.

If popItUp handler is bound first and if it returns false then data-track binding will not be called. You need to bind data-track binding first if at all you want to give it more precedence and not matter what popItUp does.

看着您已编辑的问题,data-track binding是使用live完成的,该功能适用​​于事件冒泡机制.如果popItUp处理程序returns false,则它将无法正常工作.可能是您可以尝试使用锚的e.preventDefault();来防止默认行为,而不是在popItUp处理程序中返回false.

Looking at your edited question, data-track binding is done using live which works on event bubbling mechanism. If popItUp handler returns false then it is not going to work. May be you can try to prevent default behavior using e.preventDefault(); of anchor instead of returning false inside the popItUp handler.

这篇关于jQuery如何设置绑定顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆