Blogger Information
Blog 27
fans 1
comment 2
visits 90239
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS之DOM相关操作
          
Original
523 people have browsed it

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

*自定义类数组

  1. // 数组
  2. student=['张三','李四','悟空','八戒','小白龙','悟净'];

—-执行结果

student的结果

  1. // 类数组
  2. student2={
  3. 0:'张三',
  4. 1:'李四',
  5. 2:'悟空',
  6. 3:'八戒',
  7. 4:'小白龙',
  8. 5:'悟净',
  9. length: 6
  10. };

纯数组/真数组的特征:
1.每个值对应的键名: 是从 0 开始递增正整数, 如 0,1,2,3,…

  1. 有一个length属性, 数组长度

类数组 与 纯数组的区别:
数组的构造器是 Prototype:Arry
类数组的构造器是 Prototype:Object
Arry是Object的一个子类。
应用场景:类数组‘等同于’纯数组,可用于前后端的数据读取,交互,当然也需要进行转换。

2. 获取dom元素的API有几个,使用场景是什么?

API 2个
1.获取一组数据(类数组):querySelectorAll()
2.获取一个数,返回是Dom对象:querySelector()
使用场景:获取一组或者单个对象时使用,按需选择。

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

  1. <form action="" method="post" id="login">
  2. <label for="uname"> 账户名:</label>
  3. <input type="uname" name="uname" id="uname" value="phpcn">
  4. <br>
  5. <label for="pwd">
  6. 密码:<input type="password" name="password" id="pwd">
  7. </label>
  8. <br>
  9. <button>登录</button>
  10. </form>

例如:登录表单 表单id=’login’
更优雅 - 获取表单:document.forms.login //login合法标识符 或者document.forms[‘login’]
获取input控件的value值:

  1. //先获取login表单,再获取表单里面的元素,再得到值
  2. console.log(document.forms.login.uname.value)

4. dom元素的遍历与常用API有哪些, 实例演示

  1. 常用API
  2. a = DOM节点数组
  3. 1.类数组转为真数组:Array.from()/[...类数组.children]
  4. 2.循环forEach()
  5. 3.获取第一个节点:a.firstElementChild
  6. 4.获取下一个:a.firstElementChild.nextElementSibling
  7. 5.获取最后一个:a.lastElementChild
  8. 6.获取前一个:a.lastElementChild.previousElementSibling
  9. 7.获取父节点:a.lastElementChild.parentElement

—-执行结果

实例

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!