简体   繁体   中英

How to clickEvent or fireEvent on a image by their class?

Would I be able to click a image based on their class? Example in jquery would be $(.imageID).click() ;

<img src="picture.png" class="imageClass">

How would I click event or fire event that in EXT JS 5+ ?

Ext.select('.imageClass').each(function(item){
     item.fireEvent('click', item); 
});

should fire a click event on every element of class .imageClass

You can use Ext.select() to get the behavior you're after.

 Ext.select('.pic').on('click', function() { alert('Mew!'); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all.min.js"></script> <img src="https://placekitten.com/g/200/300" class="pic" /> 

Firing UI events programmatically is very, very bad practice, unless you are testing the application. So if you are not testing, just call the handler directly and do not simulate clicks this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM