Blogger Information
Blog 34
fans 0
comment 0
visits 22519
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月17日—javascript基础第二天
曾龙宇
Original
581 people have browsed it

数组操作

push(‘元素’):往数组尾部添加一个元素

  1. var arr = ['张三','李四','王五','赵六'];
  2. console.log(arr);
  3. arr.push('老***');
  4. console.log(arr);

pop():往数组尾部弹出一个元素,返回被被弹出的元素

  1. var arr = ['张三','李四','王五','赵六'];
  2. console.log(arr);
  3. var res = arr.pop()
  4. console.log(res);
  5. console.log(arr);

unshift(‘’):往数组头部添加一个元素

  1. var arr = ['张三','李四','王五','赵六'];
  2. console.log(arr);
  3. arr.unshift('小明');
  4. console.log(arr);

shift():往数组头部删除一个元素,返回被删除的元素

  1. var arr = ['张三','李四','王五','赵六'];
  2. console.log(arr);
  3. var res = arr.shift();
  4. console.log(res);
  5. console.log(arr);

splice(startIndex,length):从数值中删除元素,返回被删除的元素

  1. var arr = ['张三','李四','王五','赵六'];
  2. console.log(arr);
  3. var res = arr.splice(1,2);
  4. console.log(res);
  5. console.log(arr);

indexOf(‘元素’):数组中查找一个元素,返回该元素的下标

  1. var arr = ['张三','李四','王五','赵六'];
  2. console.log(arr);
  3. var res = arr.indexOf('王五');
  4. console.log(res);
  5. console.log(arr);

事件

onclick:用户点击HTML元素

onchange:HTML元素发生改变

onblur:HTML元素失去焦点

onmouseover:鼠标移上HTML元素

onmouseout:鼠标离开HTML元素

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>事件</title>
  6. </head>
  7. <body>
  8. <form action="" method="post">
  9. <div>
  10. <label for="username">账号</label>
  11. <input type="text" name="username" id="username" value="" onblur="bb()">
  12. </div>
  13. <div>
  14. <label for="pwd">密码</label>
  15. <input type="password" name="password" id="pwd">
  16. </div>
  17. <div>
  18. <label for="jiguan">籍贯</label>
  19. <select name="jiguan" id="jiguan" onchange="cc()">
  20. <option value="">请选择</option>
  21. <option value="广东">广东</option>
  22. <option value="广西">广西</option>
  23. <option value="福建">福建</option>
  24. </select>
  25. </div>
  26. <div>
  27. <button type="button" onclick="aa()">提交</button>
  28. </div>
  29. </form>
  30. <button type="button" onmouseover="ee()" onmouseout="ff()">鼠标移动</button>
  31. <script>
  32. function aa() {
  33. var username = document.getElementById('username');
  34. var pwd = document.getElementById('pwd');
  35. if (username.value==''){
  36. alert('账号不能为空');
  37. username.focus();
  38. return false;
  39. }
  40. if (pwd.value==''){
  41. alert('密码不能为空');
  42. pwd.focus();
  43. return false;
  44. }
  45. alert('账号:'+username.value+' 密码:'+pwd.value);
  46. }
  47. function bb() {
  48. var username = document.getElementById('username');
  49. if (username.value==''){
  50. alert('账号不能为空');
  51. return false;
  52. }
  53. }
  54. function cc() {
  55. var jiguan = document.getElementById('jiguan').value;
  56. alert('你的籍贯是:'+jiguan);
  57. }
  58. function ee() {
  59. console.log('鼠标移上来了');
  60. }
  61. function ff() {
  62. console.log('鼠标离开了');
  63. }
  64. </script>
  65. </body>
  66. </html>

页面跳转

  1. window.location.href="http://www.baidu.com";

跳转到url对应的地址

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