jQuery.click() vs onClick

前端 未结 17 1483
情话喂你
情话喂你 2020-11-21 07:35

I have a huge jQuery application, and I\'m using the below two methods for click events.

First method

HTML

17条回答
  •  抹茶落季
    2020-11-21 08:15

    The first method of using onclick is not jQuery but simply Javascript, so you do not get the overhead of jQuery. The jQuery way can expanded via selectors if you needed to add it to other elements without adding the event handler to each element, but as you have it now it is just a question if you need to use jQuery or not.

    Personally since you are using jQuery I would stick with it as it is consistent and does decouple the markup from the script.

提交回复
热议问题