How to add click event by class name?

后端 未结 5 934
野性不改
野性不改 2020-12-31 20:45

I have a example html menu:

  • A
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 21:06

    You can find the id with this.id

    $('.menu_button').click(function() {
         if ( this.id == "m1" ) ....
     })
    

    But if the code is completely different for each button, then it may not be useful to use it like that but instead bind a different handler per id.

提交回复
热议问题