Calling jQuery method from onClick attribute in HTML

前端 未结 5 1286
半阙折子戏
半阙折子戏 2020-12-14 16:45

I am relatively new to implementing JQuery throughout an entire system, and I am enjoying the opportunity.

I have come across one issue I would love to find the corr

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 17:11

    I know this was answered long ago, but if you don't mind creating the button dynamically, this works using only the jQuery framework:

    $(document).ready(function() {
      $button = $('');
      $('body').append($button);
      $button.click(function() {
        console.log("Id clicked: " + this.id ); // or $(this) or $button
      });
    });
    
    
    

    And here is my HTML page:

    Welcome!

提交回复
热议问题