9_练习.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. #div1 {
  10. width: 200px;
  11. height: 200px;
  12. background: orange;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="div1"></div>
  18. <script>
  19. //需求 点击div 2s延迟时间 然后变为粉色
  20. /* var div1 = document.getElementById('div1')
  21. div1.onclick = function(){
  22. //保存this的值
  23. // let _this = this
  24. // setTimeout(function(){
  25. // _this.style.background = 'pink'
  26. // },2000)
  27. setTimeout(()=>{
  28. this.style.background = 'pink'
  29. },2000)
  30. } */
  31. //需求2 从给定的数组里面返回偶数的元素
  32. // const arr = [1, 6, 7, 10, 100, 25]
  33. // // const result = arr.filter(function(item){
  34. // // if(item % 2 ==0){
  35. // // return true
  36. // // } else {
  37. // // return false
  38. // // }
  39. // // })
  40. // const result = arr.filter(item => item % 2 == 0)
  41. // console.log(result)
  42. </script>
  43. </body>
  44. </html>