jQuery.click() vs onClick

前端 未结 17 1485
情话喂你
情话喂你 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 07:59

    
    

    onclick, onmouseover, onmouseout, etc. events are actually bad for performance (in Internet Explorer mainly, go figure). If you code using Visual Studio, when you run a page with these, every single one of these will create a separate SCRIPT block taking up memory, and thus slowing down performance.

    Not to mention you should have a separation of concerns: JavaScript and layouts should be separated!

    It is always better to create evenHandlers for any of these events, one event can capture hundreds/thousands of items, instead of creating thousands of separate script blocks for each one!

    (Also, everything everyone else is saying.)

提交回复
热议问题