Blogger Information
Blog 62
fans 3
comment 1
visits 29690
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js关于DOM相关操作
kiraseo_wwwkiraercom
Original
335 people have browsed it

自定义类数组,并说出与纯数组的区别与联系,哪些地方会用到类数组

代码如下

  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>自定义类数组,并说出与纯数组的区别与联系,哪些地方会用到类数组</title>
  8. </head>
  9. <body>
  10. <script>
  11. console.log("自定义类数组,并说出与纯数组的区别与联系,哪些地方会用到类数组");
  12. console.log("类数组会在操作DOM的时候用到");
  13. //纯数组
  14. const shuiguo= [' apple ' , ' orange ' ,' banner ']
  15. console.log("+++++纯数组++++");
  16. console.log(shuiguo);
  17. //类数组
  18. const yanse = {
  19. '0' : 'yellow',
  20. '1' : 'blue',
  21. '2' : 'red',
  22. };
  23. console.log("+++++纯数组++++");
  24. console.log(yanse);
  25. </script>
  26. </body>
  27. </html>

输出截图

获取dom元素的API有几个,他们的使用场景是什么

代码如下

  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>获取dom元素的API有几个,他们的使用场景是什么</title>
  8. </head>
  9. <body>
  10. <ul class="list">
  11. <li class="itmes">ime1</li>
  12. <li class="itmes">ime2</li>
  13. <li class="itmes">ime3</li>
  14. <li class="itmes">ime4</li>
  15. <li class="itmes">ime5</li>
  16. <li class="itmes">ime6</li>
  17. </ul>
  18. <span> 获取demo元素的两个api 分别是querySelectorAll和querySelector</span>
  19. <p>querySelectorAll获取的一组数据</p>
  20. <p>querySelector获取第一个数据,用于获取唯一元素,使用场景广泛,不局限与document</p>
  21. <script>
  22. console.log("");
  23. const ul = document.querySelectorAll(".list .itmes");
  24. console.log(ul);
  25. ul.forEach(function(v){
  26. console.log(v);
  27. v.style.border='1px solid blue';
  28. });
  29. console.log("++++获取ul标签并改变为背景色为黄色+++");
  30. const li =document.querySelector(".list");
  31. li.style.backgroundColor="yellow";
  32. const list = document.querySelector('.list');
  33. console.log(list);
  34. const lis = list.querySelectorAll('.itmes');
  35. lis.forEach(li => (li.style.backgroundColor = 'violet'));
  36. </script>
  37. </body>
  38. </html>

输出截图

如何优雅的获取form表单元素与控件的值

代码如下

  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>如何优雅的获取form表单元素与控件的值</title>
  8. </head>
  9. <body>
  10. <form action="login.php" method="post" id="login">
  11. <fieldset class="login">
  12. <legend>用户登录</legend>
  13. <lebel for = 'email'>邮箱</lebel>
  14. <input type="email" name="email" id="email" value="admin@qq.com" autofocus>
  15. <button>提交</button>
  16. </fieldset>
  17. </form>
  18. <script>
  19. //获取到表单
  20. console.log(document.forms.login);
  21. //获取到表单中邮箱的value值
  22. console.log(document.forms.login.email.value);
  23. </script>
  24. </body>
  25. </html>

输出截图

dom元素的遍历与常用API有哪些

代码如下

  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>dom元素的遍历与常用API有哪些, 实例演示</title>
  8. </head>
  9. <body>
  10. <ul class="list">
  11. <li class="itme">我是红色背景red</li>
  12. <li class="itme">我是绿色背景green</li>
  13. <li class="itme">我是蓝色背景blue</li>
  14. <li class="itme">我是背景色 为#fff000</li>
  15. <li class="itme">我是倒数第二个粉红色pink </li>
  16. <li class="itme">我是最后一个深粉色背景deeppink</li>
  17. </ul>
  18. <script>
  19. let data_list = document.querySelector('.list');
  20. console.log(data_list);
  21. console.log("data_list.children 只返回元素类型的节点");
  22. console.log(data_list.children);
  23. console.log("查询所有子元素节点");
  24. console.log(data_list.childNodes);
  25. // 第一个
  26. data_list.firstElementChild.style.backgroundColor="red";
  27. data_list.firstElementChild.style.color="#fff";
  28. //第二个,
  29. data_list.firstElementChild.nextElementSibling.style.backgroundColor = 'green';
  30. //第3个
  31. data_list.children[2].style.backgroundColor = 'blue';
  32. data_list.children[2].style.color="#fff";
  33. //第4个
  34. data_list.children[3].style.backgroundColor = '#fff000';
  35. data_list.children[3].style.color="#000";
  36. //最后一个为deeppink
  37. data_list.lastElementChild.style.backgroundColor="deeppink"
  38. //倒数第二个
  39. data_list.lastElementChild.previousElementSibling.style.backgroundColor = 'pink';
  40. </script>
  41. </body>
  42. </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