开发者

jquery ui: Is there a way to distinguish a 'real' event from an api call?

I am using tabs from jquery ui where a select-callback is included, working as expected. At one point of the script I need to do a select-method call that also triggers the callback which is not wanted at that point.开发者_JAVA百科

What I am looking for is some difference in the event-parameter of the callback which could be used in an if-clause to prevent the contents from the callback to be executed..

I tried stopPropagating, but then the default tab functions are not executed either (the classes are not reset)

I hope someone understands what I am looking for :)

thanks in advance


To distinguish a real event from a programmatically generated one you should check for event.originalEvent wich is undefined if the event is generated programmatically

for example:

<button id='my'>Click me</button>
<button id='my2'>Click the other</button>

$('#my2').click(function(){
    $('#my').click();
});

$('#my').click(function(event){
    if (event.originalEvent === undefined){
        alert('computer');
    }else{
        alert('human');        
    }
});

fiddle here: http://jsfiddle.net/uqNHd/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜