Talking about the loop binding handler in JS closures _ basic knowledge-js tutorial

Source: Internet
Author: User
What beginners often encounter is getting HTML element sets and adding events to elements cyclically. Obtain the corresponding index in the Event Response Function (eventhandler. However, each query is the index of the last loop. The reason is that beginners do not understand the closure feature of JavaScript. When I was writing front-end js Code a few days ago, I encountered a traversal element to add a click event to it. That's why I spent the whole afternoon. Finally, I went home from work and checked the information online to find out how to solve the problem. (PS: I have also read the content about the loop binding handler in the fourth edition of jQuery basic tutorial. I didn't think it was easy at that time, so I didn't remember it .)
If you know this kind of situation, you can close the window and write it to the white ones like me. Thank you!

First, paste an incorrect example for your reference. (JQuery is used in this example. Import the jQuery library)

The Code is as follows:





  
  Loop binding Handler
  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.