使用“on”附加事件后验证

时间:2014-01-06 12:03:42

标签: jquery

我之后使用“on”附加了一个事件我想验证控件是否包含此事件。

示例:

//adding an event
$("#divControls").on('change',".myclass input", myfunction());

//verifying the event

if($(".myclass input"].change)
{
   // logic
}

我该怎么做?

3 个答案:

答案 0 :(得分:1)

因为它是委托事件,你只需要检查父母:

var $inputWithBoundChange = $(".myclass input").filter(function(){return $(this).closest('"#divControls"').length})

这将返回.myclass元素内的所有输入,该元素已委托事件已绑定。

答案 1 :(得分:0)

试试这个

 $(document).on('change',"#divControls .myclass input", myfunction);

答案 2 :(得分:0)

您可以尝试迭代绑定到该元素的事件。

 jQuery.each($('#divControls').data('events'), function(i, event){

    jQuery.each(event, function(i, handler){

        console.log( handler.toString() );

    });

});
相关问题