├── style.css ├── script.js └── index.html /style.css: -------------------------------------------------------------------------------- 1 | li { 2 | height: 25px; 3 | } -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | const colors = ['red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'magenta'], 2 | lis = document.querySelectorAll('li'); 3 | console.dir(lis); 4 | 5 | lis.forEach((li,i)=>{ 6 | li.addEventListener('click', paint()); 7 | }); 8 | 9 | function paint() { 10 | var i = 0; 11 | return function (){ 12 | this.style.backgroundColor = colors[i%colors.length]; 13 | i++; 14 | }; 15 | }; -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |