简体   繁体   中英

bind function not working in javascript

This is the html I am using

  <div class="col-md-12 col-sm-12 text-center permissions-submit">
          <button class="btn btn-primary ">Set Permissions</button>
 </div>
//remove extra ending div

Now I have written a method named bindEvents which would do the following

 bindEvents : function(){
        this.$elSubmit = $('.permissions-submit');
        this.$elSubmitButton = this.$elSubmit.find('button');
        console.log('submit',this.$elSubmitButton);
        this.$elSubmitButton.on('click',this.permissionsSubmit.bind(this));
    }

The issue is that,nothing happens on the button click. It is supposed to call the method "permissionsSubmit".

why don't you try this as it's mentioned on jQuery API.

 $( "#foo" ).bind( "click", function() {
        //Do your work here
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM