Blogger Information
Blog 36
fans 1
comment 0
visits 28748
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月17日JS基础(数组,增删改,DOM事件)-九期线上班
WJF
Original
860 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 arr1 = new Array('a','b','c','d');
  11. // console.log(arr1);
  12. //数组定义 2
  13. var arr2 = ['e','f','g'];
  14. // console.log(arr2);
  15. //push()给数组尾添加元素
  16. var arr3 = ['a','b','c'];
  17. arr3.push('d');
  18. // console.log(arr3);
  19. //pop()删除数组最后一个元素
  20. var arr4= ['a','c','e','f'];
  21. arr4.pop();
  22. // console.log(arr4);
  23. //unshift()给数组开头添加元素
  24. var arr5=['z','x','c','v'];
  25. arr5.unshift('q','a');
  26. // console.log(arr5);
  27. //shift()删除数组开头元素
  28. var arr6=['a','s','d','f','g','h'];
  29. arr6.shift();
  30. arr6.shift();
  31. // console.log(arr6);
  32. //slice()在数组内选定元素 返回
  33. var arr7=['q','w','e','r','t','s','a','t'];
  34. var res1 = arr7.slice(0,3);
  35. // console.log(res1);
  36. //concat()多个数组进行连接
  37. var res2 = arr1.concat(arr2.concat(arr3));
  38. // console.log(res2);
  39. //indexOf 返回指定数组的下标
  40. var res3 = arr7.indexOf('t');
  41. // console.log(res3);
  42. //Array.isArray()判断对象是否为数组
  43. var no = '666666666aaa6sd6a]d4sa';
  44. var res4 = Array.isArray(no);
  45. // console.log(res4);
  46. //join():把数组转化为字符串
  47. var arr8 = ['a','c','d','b'];
  48. var res5 = arr8.join('---');
  49. // console.log(res5);
  50. //includes()判断数组是否包含指定值
  51. var res6 = arr8.includes('q');
  52. console.log(res6);
  53. </script>
  54. </body>
  55. </html>

JS DOM事件


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>JS DOM事件</title>
  6. </head>
  7. <body>
  8. <button onclick="d()">单击我</button>
  9. <button ondblclick="s()">双击我</button>
  10. <button onmouseover="y()">移到我</button>
  11. <button onmouseout="l()">离开我</button>
  12. <input type="text" onblur="j()" placeholder="请输入!">
  13. <script>
  14. //onclick()当用户单击该元素调用的事件
  15. function d() {
  16. alert('被单击我就出来了');
  17. }
  18. //ondblclick()当用户双击该元素调用的事件
  19. function s() {
  20. alert('被双击我就出来了');
  21. }
  22. //onmouseover()鼠标移到该元素
  23. function y() {
  24. console.log('碰到我了!')
  25. }
  26. //onmouseout()鼠标离开某元素
  27. function l() {
  28. console.log('离开我了!!!')
  29. }
  30. //onblur()失去该元素焦点
  31. function j() {
  32. alert('离开输入框')
  33. }
  34. </script>
  35. </body>
  36. </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