Based on the difference between this and event in js (detailed description), jsevent
Today, you can see this and event parameters in the event chapter, a typical introduction to javascript. As a beginner front-end developer, I only use this to pass parameters. so I 'd like to find out what is the difference between this and event, and what is appropriate under what circumstances.
Onclick = changeImg (this) vs onclick = changeImg (event)
<script> var myImages = [ 'usa.gif','canada.gif','jamaica.gif','mexico.gif' ]; function changeImg(e) { var el = e.target; var newImgNumber = Math.round(Math.round()*3); while(el.src.indexOf(myImages[newImgNumber]) != -1){ el.src =myImages[newImgNumber]; } }</script>
1. this is a keyword in Javascript.
2. this indicates an internal object automatically generated when the function is running. It can only be used inside the function.
3.thisvs event.tar get:
Events in JSS are fraudulent, so thiscan be changed, but event.tar get does not change (when an event is triggered, only the reference of the current event object is passed). It is always the target DOM element that directly accepts the event;
In addition, thisand event.tar get are dom objects. If you want to use methods in jquey, you can convert them to jquery objects: sums (this(and counts (event.tar get );
Based on the difference between this and event in js (detailed description), this is all the content shared by Alibaba Cloud xiaobian. I hope you can provide a reference and support for the customer's house.