Blogger Information
Blog 36
fans 1
comment 0
visits 28783
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月18日JS基础(JS对象,JS定时器)-九期线上班
WJF
Original
845 people have browsed it

JS对象


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>JS对象</title>
  6. </head>
  7. <body>
  8. <script>
  9. //创建对象方法1
  10. var obj1 = new Object();
  11. obj1.name = 'WJF';
  12. obj1.age = 17;
  13. obj1.fa = function (data) {
  14. console.log('传参:'+data);
  15. };
  16. console.log(obj1.name + '同学' + obj1.age + '岁了');
  17. // alert(obj1.name + '同学' + obj1.age + '岁了');
  18. console.log(obj1.fa('PHP中文网 www.php.cn'));
  19. //创建对象方法2
  20. var obj2 = {name: "WJF",email: "33703259@qq.com"};
  21. obj2.age = 17;
  22. console.log(obj2);
  23. //v创建对象方法3
  24. var obj3 = {
  25. name:"WJF",
  26. email: "33703259@qq.cn",
  27. fa: function (data) {
  28. console.log(data);
  29. }
  30. };
  31. console.log(obj3.fa('6666'));
  32. //4
  33. var obj4 = {
  34. name: "WJF",
  35. age: 17,
  36. get: function () {
  37. console.log(obj4.age);
  38. },
  39. fa: function () {
  40. console.log(obj4.name);
  41. }
  42. };
  43. console.log(obj4.fa());
  44. </script>
  45. </body>
  46. </html>

JS定时器


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>JS定时器</title>
  6. </head>
  7. <body>
  8. <script>
  9. //setTimeout()执行一次
  10. setTimeout(function () {
  11. console.log('1000ms')
  12. },1000);
  13. //setInterval()重复执行
  14. setInterval(function () {
  15. console.log('1000ms重复')
  16. },1000);
  17. //clearInterval()消除定时器
  18. var time = setInterval(function () {
  19. console.log('重复1000ms')
  20. },1000);
  21. setTimeout(function () {
  22. clearInterval(time)
  23. },4000);
  24. </script>
  25. </body>
  26. </html>

发送验证码


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>发送验证码</title>
  6. </head>
  7. <body>
  8. <button id="text">发送验证码</button>
  9. <script>
  10. var button = document.getElementById('text');
  11. button.addEventListener('click',function () {
  12. var text = document.getElementById('text').textContent;
  13. var time = 60;
  14. var val = setInterval(function () {
  15. document.getElementById('text').textContent = time+'秒后重试';
  16. time --;
  17. if (time == 0){
  18. clearInterval(val);
  19. document.getElementById('text').textContent = text;
  20. }
  21. },1000);
  22. });
  23. </script>
  24. </body>
  25. </html>
Correction status:Uncorrected

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