1

一部のイベントが既に要素にバインドされているかどうかを確認する必要があります。

例えば

$(".animate").click(function(){
    alert('Here comes action');
}); 

$(".someOtherSelector").click(function(){
    alert('some other action');
});

HTML

<a class="animate"></a>
<a class="someOtherSelector animate"></a>

2 番目の関数では、この要素に既にバインドされているイベントがあるかどうかを確認する必要があります。もしそうなら、それは実行されるべきではありませんalert('some other action');

jQuery バージョン 1.10.1 を使用しています。

4

2 に答える 2

4

jQuery 1.8以降、はdataevent dataに使用できなくなりました。このjQuery ブログ投稿を読んでください。これを使用する必要があります:

jQuery._data(element, "events")

コード

$('.someOtherSelector').each(function(){
    console.log($._data(this, "events"));
});

フィドル

于 2013-10-04T12:46:03.313 に答える