简体   繁体   English

有没有一种方法来获取所有default_event_actions,然后使用jQuery中的event.preventDefault()阻止除某些对象之外的其他对象?

[英]Is there a way to get all default_event_actions, then prevent some except others with event.preventDefault() in jQuery?

I'd like to know if is there a way to have a list of the default_event_actions for a particular element that ' event.preventDefault() ' has been applied on and tell the script what event or action to prevent or not... 我想知道是否有一种方法可以为已应用' event.preventDefault() '的特定元素提供default_event_actions的列表,并告诉脚本要阻止或不阻止的事件或动作...

something like: 就像是:

$(element).on('click', function(e){

e.preventDefault() //this will prevent all

//...is there a way of preventing specifically or particularly... 
}) 

Is it possible? 可能吗?

You can use e.type to check type of event and based on condition can prevent default for example: 您可以使用e.type来检查事件的类型,并且基于条件可以防止发生默认情况,例如:

$(element).on('click', function(e){
    if(e.type == 'click')
        e.preventDefault(); //this will prevent all
    }
});

You can use jQuery event namespaces to give unique name to your events : event.namespace 您可以使用jQuery事件名称空间为事件指定唯一名称: event.namespace

And to find all events attached to a particular element, you can look at Jonathan Sampson's answer for this question (Can I find events bound on an element with jQuery?) 要查找附加到特定元素的所有事件,可以查看乔纳森·桑普森(Jonathan Sampson)对这个问题的回答(我可以用jQuery找到绑定在元素上的事件吗?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM