this is a common closure problem:
I would like to ask you guys, how is this code executed?
for example, when you click 3, how do you print out 2?
< script >
var elem = document.getElementsByTagName("div"); // 5div
for (var i = 0; i < 5; iPP) {
console.log(i);
(function (w) {
elem[w].onclick = function () {
console.log(w);
};
})(i);
}
< / script >
for loop comes from I. When you click on it, the argument I is passed to the parameter w. When you click on the third element, the div content starts at 1
your div content starts at 1, and the index for the loop starts at 0, so the pop-up value will be 1
when you click on the third element. 1-5
I starts with 0, 0-4
so when you click on div3, the third bit is 2, because 0 is the first bit of I, 1 is the second bit of I, and 2 is the third bit of I
var elem = document.getElementsByTagName('div'); // 5div
for (var i = 0; i < 5; iPP) {
console.log(i);
(function (w) {
elem[w].onclick = function () { -sharp idiv
console.log(w);
};
})(i); -sharp 0-4
}
"immediate execution function" retains the value of each "I" and binds each "div" separately,
so when you click "div3", Will output "2"
(starting at 0, so it is 2)
Previous: Bootstrap modal box failure $(.). Modal is not a function
Next: Error caused by single quotation marks in sql statement
-
Multiple choice questions, how to judge whether the chosen answer is the correct answer?
I got a set of data, which is to choose the type of question. How can I tell if I have chosen the right one answera: "Olympic Games " answerb: "Asian Games " answerc: "Paralympic Games " answerd: "University Games " id: "1772 " question: "f...
Feb.26,2021 -
What is the current level of support for vw,vh layouts in mobile browsers?
what is the current level of support for vw,vh layouts in mobile browsers? ...
Feb.26,2021 -
On the problem of using relative paths to introduce pictures in ant-design-pro-site
modify the markdown file under the ant-design-pro-site site and use the relative path to introduce the picture in the markdowm file. attachment: the picture was originally introduced using the http path. <img src=". images 1.jpg" > ...
Feb.27,2021 -
As shown in the red border, select the effect of input.
Icon shows the red part. Choose how to write the effect in css ....
Feb.27,2021 -
The content of element-ui table is not centered vertically
how to make the content of table not be centered vertically? you can set valign= "top " in html, then how to set it in element The table is centered vertically when it is stretched out, and the working hours are aligned with the one at 8 o clock . ...
Feb.28,2021 -
Warnings during webpack Hot UPDAT
error WARNING in configuration The mode option has not been set. Set mode option to development or production to enable defaults for this environment. WARNING in asset size limit: The following asset(s) exceed the recommended size limi...
Feb.28,2021 -
Now you need to do a front-end page for ipad pro2. Ui gave me the blueprint, would you like to set my page to be the same size?
now you need to make a front-end page for ipad pro2. Ui gave the design drawing 2732 to 2048. Should my page be set to the same size ?...
Feb.28,2021 -
The display of the page under chrome is blurred.
A static page is written on the computer, and the text and pictures are displayed vaguely under chrome. I can t bear to look directly at it, but it s okay to display it under Firefox. It is no problem for chrome to open other pages, just write this pag...
Mar.01,2021 -
Front-end rookie, how to understand UI diagram?
A rookie at the front end, get the UI picture and do the website. The following CSS Rem 12pxterCSS Rem 14pxtransCSS Rem 14px; , how on earth should I choose? my current understanding: `CSS Rem 12px;` width= 40rem; `CSS Rem 16px;` width= 30rem; ...
Mar.01,2021 -
Has anyone ever done anything like JD.com, where the page scrolls down and the content is gradually rendered and inserted?
I haven t done it. I want to know what the train of thought is . Does first store each section structure as a string, then scroll to the specified location, and execute the following code? is similar to paging loading, but the content and layout of ...
Mar.01,2021 -
How to modify the data rendered by v-for and then bind the style?
<tr v-for="item in tableData"> <td :class="same">{{item.td}}< td> < tr> computed:{ same(){ let arr = ???.push( c ); return{ red: arr == [ a , c ] } } } here? It should be the dat...
Mar.02,2021 -
How to use Select components in ant design in ant design mobile
in using ant design mobile, you need to use the kind of Select component in antd, but it is not in ant design mobile. What should I do ...
Mar.02,2021 -
Click upload of html added by layui.upload.render with js is invalid
$("-sharpadd_link").click(function(){ var link_html = "<div class= "linkAll_inn ">" + "<div class= "activity_theme ">" + ...
Mar.02,2021 -
Delay of page rendering after element style change in webapp
The problem with is roughly as follows: there is a list page with a title bar in the middle. When I pull up a certain distance, the title bar is fixed and suspended at the top, and when pulled down a certain distance, it is put back to its original pos...
Mar.03,2021 -
How to solve the problem that it takes too long for a website to load local personalized fonts?
the question is as perplexed as the title. Design website, using personalized fonts, such as: the following three fonts, so download online, import locally. ...
Mar.03,2021 -
Looking for a way to switch between Chinese and English on the official website?
company website, pure static text, would like to ask how to quickly achieve a Chinese-English switching function? some methods have been tried so far, such as method 1: translate the whole document directly with Microsoft js file , but this metho...
Mar.03,2021 -
Verification code style problem
how is the style of CAPTCHA realized? how to find the principle! question: is there an input for each number? Find the solution ...
Mar.04,2021 -
1. What can I do to make the width of a div change from left to right? 2. Dynamically drag and edit multi-level header
means that the width on the right side of the div is fixed, pull the left border, and the width shrinks from left to right div1,div2. div2div1div2 tablediv ...
Mar.04,2021 -
After vue routes are configured with child routing paths, $router.push cannot switch routes, as shown below
< html lang= "en " > < head > <meta charset="UTF-8"> <title>Document< title> <script type="text javascript" src="vue.js">< script> <script type="text javascript" src="vue...
Mar.04,2021 -
On the iframe scroll bar problem under ie, remove the event question?
A question I was asked by the back end a few days ago, because the background page is compatible with ie8, it should be carried out under ie. gives iframe a move-out event, which is triggered as soon as the mouse moves over the scroll bar when the mouse...
Mar.05,2021
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3acf8-e792.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-1b3acf8-e792.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?