index.html 608 B

123456789101112131415161718192021222324252627
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>JS-classwork-closure</title>
  7. </head>
  8. <body>
  9. <button id='button1'>button1</button>
  10. <button id='button2'>button2</button>
  11. <script>
  12. // let counter = 0;
  13. function clickCounter (element) {
  14. let counter = 0;
  15. element.onclick = function () {
  16. // let counter = 0;
  17. return element.innerText=counter++;
  18. }
  19. }
  20. clickCounter (button1);
  21. clickCounter(button2);
  22. </script>
  23. </body>
  24. </html>