How to run a callback function on a jQuery trigger(“click”)?

后端 未结 8 1901
太阳男子
太阳男子 2021-01-03 18:44

I need to trigger a custom event in the callback of a trigger call, but I can\'t get it to work.

I tried this:

var $input = $( \".ui-pop         


        
8条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-03 19:16

    If you have a click handler on every input but want to do something on a specific element:

    var $container = $(".ui-popup-container"),
        special = 2;
    
    $container.on('click', 'input', function() {
        // do something for every input
    
        if($(this).index() == special) {
            // your "callback", e.g. the function you want to execute on input:eq2 click
            myfunction();
        }
    }).find('input').eq(special).trigger('click');
    

提交回复
热议问题