Binding an existing JavaScript function in jQuery

后端 未结 4 1953
夕颜
夕颜 2020-12-24 13:09

Using jQuery I want to bind an existing function to a button. I\'ve been through the documentation and have found the bind method but the examples on the jQuery

4条回答
  •  半阙折子戏
    2020-12-24 13:52

    Yes you can bind methods that written somewhere else, but you should ignore the parentheses :

    function fHardCodedFunction(){
       //Do stuff
    }
    
    function fBindFunctionToElement(){
       $("#MyButton").bind("click", fHardCodedFunction);
    }
    

提交回复
热议问题