Blogger Information
Blog 43
fans 0
comment 3
visits 26846
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 理解访问器属性原理与应用场景,并实例演示 2. 实例演示获取dom元素的二个重要方法
Time
Original
321 people have browsed it

访问器属性原理与应用

原理:将传统方法伪装成属性

  1. let data ={
  2. age:18,
  3. set age(age){
  4. if(age>=18 && age<120){
  5. this.data.age = age;
  6. }
  7. }
  8. get age(){
  9. return this.data.age;
  10. }
  11. }
  12. console.log(data.age);
  13. data.age = 8888;
  14. cosole.log(data.age);

访问器属性应用场景:双性绑定、数据响应式

获取dom元素的二个重要方法

1.querySelectorAll返回一组元素

  1. console.log(document.querySelectorAll.('.item'));

2.querySelector返回一个元素,一组元素的第一个

  1. console.log(document.querySelector.('.item'));
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