Blogger Information
Blog 29
fans 0
comment 0
visits 19626
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js事件解决生发问题
牡丹飞
Original
601 people have browsed it

1 效果

2 代码

  1. let secret = document.querySelector(".container > p > strong");
  2. onClickDoing = (ev) => {
  3. switch (ev.target.innerHTML) {
  4. case "自然睡":
  5. secret.innerHTML = "困了就睡,那怕是在工作,只要你的工作不是一停就会受伤!";
  6. break;
  7. case "自然醒":
  8. secret.innerHTML = "醒了就起,那怕起来洗漱一下,再睡回笼,因为你有困了!";
  9. break;
  10. case "吃饭慢":
  11. secret.innerHTML = "慢的标准是,吃的东西你都知道是什么味道,什么东西!";
  12. break;
  13. case "饱要停":
  14. secret.innerHTML = "知道味道和东西,你就会关注肚皮的感觉,饱了就不要吃了,当然要你乐意!";
  15. break;
  16. case "关注会":
  17. secret.innerHTML =
  18. "知识点很多时,多关注你学会的,学不会的再写几次就好,不要关注他,不要骄傲啊,你是个天才!";
  19. break;
  20. default:
  21. secret.innerHTML = "告诉你个秘密哦!!";
  22. break;
  23. }
  24. };
  25. document.querySelector(".btn").addEventListener("click", (ev) => onClickDoing(ev), false);
  26. const ev = new Event("click");
  27. //不绑定不能用自动触发事件
  28. let btnList = document.querySelectorAll(".btn > button");
  29. for (v of btnList) {
  30. v.addEventListener("click", (ev) => onClickDoing(ev), false);
  31. }
  32. //自动循环点击事件
  33. let i = 0;
  34. setInterval(() => {
  35. if (i < 5) {
  36. btnList[i].dispatchEvent(ev);
  37. i++;
  38. } else {
  39. i = 0;
  40. }
  41. }, 2000);

3 总结

感谢老师教导!
学到了事件,字符串和数组常用函数!
有事儿发生了,咱们的服务要跟上。
加自动点击功能。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:这是追评吗?这个作业很眼熟, 不过, 写得不错
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post