Why the event click function does not work. ClassName [I] .className

for (var iBoth I < buttons.length;iPP) {

    buttons[i].onclick=function(){
    
    var myIndex=this.getAttribute("index");
    var indexOffset=parseInt(myIndex-index)*(-600);
    animate(indexOffset);
    index=myIndex;
    this.className="on";// this 

}
}

Mar.21,2021

for(var i=0;i<buttons.length;iPP){

    buttons[i].onclick=function(e){
    
    var myIndex=this.getAttribute('index');
    var indexOffset=parseInt(myIndex-index)*(-600);
    animate(indexOffset);
    index=myIndex;
    e.target.className='on';// this 
}
}

that's fine

I don't want to explain why e.target and this can, but buttons [I] can't but for (let i; i < buttons.length; PPi), and what's the difference between e.currentTarget and e.target.

Don't torture me


Brother, you don't quite understand the pointing problem of event and this. In an event, this points to the current element. For example, if you bind a click event to each button, then this refers to the current one you click on, and event.target is the current element, so the two are conceptually the same. On the other hand, currenttaret means that there is little difference between the current elements of the binding event, because the specific aspects used are different, so it depends on the requirements

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e41e30-4497a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e41e30-4497a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?