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

后端 未结 8 1942
太阳男子
太阳男子 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:03

    You need to use bind or on to add callbacks. In your case it should look like this:

    var $input = $( ".ui-popup-container" ).find( "input" ).eq(2);
    
    function runtests () {
        console.log("clicked the input");
    };
    
    $input.bind('click', runtests);
    

    Even shorter version for binding click is $input.click(runtests)

    Then it will be called on click or you can trigger it manually with $input.trigger('click') or simply $input.click().

提交回复
热议问题