search

Home  >  Q&A  >  body text

javascript - How to implement batch click events in Angular2?

1. You need to set click events for all images, including the img tag in the html that is added later.
2. How to add click events to all img.
3. Is there a method similar to $().on?

世界只因有你世界只因有你2751 days ago823

reply all(1)I'll reply

  • 迷茫

    迷茫2017-06-26 10:52:54

    var imgs = ..... // 获取你要的img标签
    
    Array.prototype.forEach.call(imgs, function (img) {
        img.addEventListener('click', function () {
            // do something
        })
    })
    

    As long as the code is written in js, all native methods can be used.

    reply
    0
  • Cancelreply