Blogger Information
Blog 16
fans 0
comment 1
visits 8487
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
保存用户设置练习
浅若夏沫
Original
593 people have browsed it

没有使用cookies,但功能都做出来了

  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. .text{
  10. width:300px;
  11. height:300px;
  12. border:1px solid black;
  13. }
  14. .btn{
  15. line-height:30px;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div class="text">天堂旅行团</div>
  21. <div class="btn">
  22. <button id="bjys">改变背景颜色</button>
  23. <button id="ztys">改变字体颜色</button>
  24. <button id="size">改变字体字号</button>
  25. </div>
  26. <script>
  27. var text=document.querySelector('.text');
  28. var bjys=localStorage.getItem('bgColor') || '#fe3212';
  29. var ztys=localStorage.getItem('color') || 'black';
  30. var size=localStorage.getItem('fontSize') || '20px';
  31. text.style.background=bjys;
  32. text.style.color=ztys;
  33. text.style.fontSize=size;
  34. document.querySelector('#bjys').onclick = function () {
  35. bgColor = prompt('请输入要修改的颜色');
  36. localStorage.setItem('bgColor', bgColor);
  37. text.style.background = bgColor;
  38. }
  39. document.querySelector('#ztys').onclick = function () {
  40. color = prompt('请输入字体的颜色');
  41. localStorage.setItem('color', color);
  42. text.style.color = color;
  43. }
  44. document.querySelector('#size').onclick = function () {
  45. fontSize = parseInt(prompt('请输入要修改的字体大小')) + 'px';
  46. localStorage.setItem('fontSize', fontSize);
  47. text.style.fontSize = fontSize;
  48. }
  49. </script>
  50. </body>
  51. </html>






Correcting teacher:PHPzPHPz

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