123456789101112131415161718192021222324252627 |
- <!DOCTYPE html>
- <html lang="ru">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>JS-classwork-closure</title>
- </head>
- <body>
- <button id='button1'>button1</button>
- <button id='button2'>button2</button>
- <script>
- // let counter = 0;
- function clickCounter (element) {
- let counter = 0;
- element.onclick = function () {
- // let counter = 0;
- return element.innerText=counter++;
- }
- }
- clickCounter (button1);
- clickCounter(button2);
-
- </script>
- </body>
- </html>
|