jQuery different events on different elements to trigger the same function

前端 未结 3 606
旧巷少年郎
旧巷少年郎 2021-01-21 17:40

What if different elements have to trigger the same function but on different events ?

$(\'#btnNext\').on(\'click\', function() { /*Same thing*/ });

$(\'#txtFie         


        
3条回答
  •  清歌不尽
    2021-01-21 18:02

    $('#btnNext').on('click', myMethod );
    
    $('#txtField').on('change blur',  myMethod );
    
    function myMethod()
    {
    /*Your Code goes here*/
    }
    

提交回复
热议问题