Blogger Information
Blog 27
fans 0
comment 0
visits 17332
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
033-12月17日-JS第2节-数组、事件等
冇忉丼
Original
602 people have browsed it

数组的一些方法:

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <script>
  12. var arr = ['a','b','c','d'];
  13. var arr2 = [1,2,3,4,5,6];
  14. arr2.unshift(555);
  15. console.log(arr2);
  16. arr.push('h');
  17. console.log(arr);
  18. arr[8] = 'm';
  19. console.log(arr[7]);
  20. console.log(arr);
  21. var res = arr.pop();
  22. console.log(arr.shift());//弹出头部元素,php中也有类似用法
  23. arr.unshift('n');//添加头部元素
  24. console.log(arr);
  25. arr.splice(5,3);//从中间删除元素第二个参数为个数
  26. console.log(arr);
  27. console.log(arr.indexOf('y'));//查找元素的索引,查不到返回-1,php的in_array是数组是否存在此值,对应的php中的函数为strripos("Hello world!","WO")
  28. arr.indexOf('b',3);//从第4个元素开始找
  29. </script>
  30. </body>
  31. </html>

事件等

1.BOM操作(1): window.location.href = “https://www.baidu.com";打开页面直接跳转
2.事件
(1)<a href='javascript:;' onclick='xxx'>//先在标签里绑定事件
onmouseover(鼠标移到某元素之上时) onmouseleave(鼠标离开某元素时) onblur(元素失去焦点时) onchange(用户该表域的内容改变时)等
(2)js中定义事件触发后的操作
function xxx() {//onclick事件触发此函数
var username = document.getElementById(‘username’).value;

}
3.前端判断为了界面,后端判断为了安全

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