Blogger Information
Blog 28
fans 0
comment 0
visits 15773
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
07-12作业
︷肉園耔︷
Original
480 people have browsed it
  • 代码区
    — 作用域和闭包
    ```

    <script>
    let staff={
    id:1,

    1. name:"朱老师",
    2. age:20,
    3. setAge(age){
    4. if(age >=18 && age <60 ){
    5. return (this.age=age);
    6. }
    7. console.log("年龄:(18-60)之间");
    8. }, };

    console.log(‘age=’,staff.age);
    console.log(‘name’,staff.name);
    staff.setAge(65);

let staff={
data:{id:1,name:”朱老师”,age:20,},
setAge(age){if(age>=18 && age <60){
return (this.data.age=age);
}
console.log(“年龄:(18-60)之间”);
},
};
console.log(staff.data.age);
staff.setAge(40);
console.log(staff.data.age);

访问属性
1.读属性

2.写属性

let staff={
data:{id:1,name:”朱老师”,age:20},
//读取的”访问起属性”
get age(){
console.log(“aaa”);
return this.data.age;
},
set age(age){if(age >=18 && age<60){
return(this.data.age=age);
}
console.log(“年龄:(19-60)之间”);
}
};
console.log(staff.age);
staff.age=81;
console.log(“age=”,staff.age);

块作用域

if(true){
var a =10;
let a=15;
console.log(“a”,a);
}
console.log(“a=”,a);

function demo1(a){
let b=20;
console.log(“a=%d,b=%d”, a , b);
}
demo1(10);
console.log(15,31);

function parent(){
let m =500;
return function (a){
let b=2;
console.log(a,b,m);
};
}
let f =parent();
console.log(f);
f(4);

console.log(parent());
parent(4);
push推动 从尾部添加字母
let arr=[];
console.log(arr.push(“a”));
console.log(arr);
console.log(arr.push(“b”,”c”,”d”));
console.log(arr);

  1. pop(无参数) 从尾部删除
  2. console.log(arr.pop());
  3. console.log (arr);
  4. unshift从头部添加
  5. console.log(arr.unshift(1,2,3));
  6. console.log(arr);
  7. console.log (arr.shift());
  8. console.log(arr);
  9. arr=["html" ,"css","js"];
  10. let res=arr.join();
  11. console.log(arr);
  12. res=arr.join("---");
  13. console.log(res);
  14. les= arr.join("</li><li>");
  15. console.log(les);
  16. console.log('<ul><li>$<res></ul></li>');
  17. //document.body.insertAdiacentHTML("beforeend",html);
  18. //cancat():
  19. console.log("hello".concat("php.cn"));
  20. console.log(["hello"].concat(["php.cn"]));
  21. //splice()实现数组的增删改查的操作
  22. arr=[1,2,3,4,5];
  23. res =arr.splice(3,1);
  24. console.log(res);
  25. //res=arr.splice(2,0,"html","css");
  26. res=arr.splice(3,0, ...["php","js"]);
  27. console.log(res);
  28. console.log(arr);
  29. //更新操作,即删除又新增
  30. res=arr.splice(2,1,"javascript");
  31. console.log(res);
  32. console.log(arr);
  33. //forEach() 对数组中的每一个成员使用一个回调方法进行处理
  34. const items = document.querySelectorAll("li");
  35. items.forEach(function(item){
  36. item.style.color="red";
  37. })
  38. document.querySelectorAll("li").forEach(xxx=>(xxx.style.color="red"));

//filter()对数组中的每个使用回调方法进行处理,只返回数据为true的元素
arr=[1,2,3,4,5,6,7,8];
res=arr.filter(a=>!(a%2));
console.log(res);

reduce();归并操作,将数组中的所有元素指定的回调处理一个单一结果返回
arr=[1,2,3,4,5];
res=arr.reduce(function(prev,curr){
console.log(prev,curr);
return prev+curr;
});

  1. res=arr.reduce((prve,curr)=>prve+curr);
  2. console.log(res);

arr=[5,6,7,8,9,12,13,14,15];
res=arr.reduce(function(prev,curr){
console.log(prev,curr);
return prev+curr;
});
res=arr.reduce((prve,curr)=>prve+curr);
console.log(res);

  1. user={
  2. 1:1,
  3. 2:"name",
  4. 3:"admin@php.cn",
  5. length:3,

}
for(let item of Array.from(user)){
console.log(item);
}
/* let staff={
id:1,
name:”朱老师”,
age:20,
setAge(age){
if(age >=18 && age <60 ){
return (this.age=age);
}
console.log(“年龄:(18-60)之间”);
},
};
console.log(‘age=’,staff.age);
console.log(‘name’,staff.name);
staff.setAge(65);

let staff={
data:{id:1,name:”朱老师”,age:20,},
setAge(age){if(age>=18 && age <60){
return (this.data.age=age);
}
console.log(“年龄:(18-60)之间”);
},
};
console.log(staff.data.age);
staff.setAge(40);
console.log(staff.data.age);

访问属性
1.读属性
2.写属性

let staff={
data:{id:1,name:”朱老师”,age:20},
//读取的”访问起属性”
get age(){
//console.log(“aaa”);
return this.data.age;
},
set age(age){if(age >=18 && age<60){
return(this.data.age=age);
}
console.log(“年龄:(19-60)之间”);
}
};
console.log(staff.age);
staff.age=81;
console.log(“age=”,staff.age);

块作用域

if(true){
var a =10;
let a=15;
console.log(“a”,a);
}
console.log(“a=”,a);

function demo1(a){
let b=20;
console.log(“a=%d,b=%d”, a , b);
}
demo1(10);
console.log(15,31);

function parent(){
let m =500;
return function (a){
let b=2;
console.log(a,b,m);
};
}/
/
let f =parent();
console.log(f);
f(4);
const items= document.querySelectorAll(‘.list .item’);
console.log(items);
Array.from(items).forEach(item => (item.style.color=”red”));

console.log(items[0]);
items[0].style.background=”yellow”;
//返回满足条件的元素集合第一个,常用来返回唯一元素
const first = document.querySelector(“.list .item “);
console.log(first);
console.log(first===items[0]);
const ul = document.querySelectorAll(“.list”);
console.log(ul);

const ul=document.querySelector(“.list”);
console.log(ul);
body
const body = document.querySelector(“body”);
body.style.backgroundColor=”lightcyan”;

console.log(document.head);

let $ =function(selector){
return document.querySelector(selector);
}
console.log($(“ul”));

let $ =selector=>document.querySelector(selector);
let $ =selector=>document.querySelector(selector);
console.log($(“body”).style.backgroundColor=”lightcyan”);

  1. 表单获取的特殊性

const form= document.querySelector(“#IN”);

console.log(form);
document.forms获取表单ID选择器和nama
console.log(document.forms.IN);
console.log(document.forms.FM);
console.log(document.forms.IN === document.forms.FM);
console.log(document.forms.IN.login.value);
//DOM树中的所有内容成为节点
//节点类型:元素,文本,文档
let ul=document.querySelector(‘.list’);
console.log(ul.childNodes);

  1. //children
  2. //Array.from(ul.children).forEach(item=>(item.style.color="red"));
  3. //[...ul.children].forEach(item=>(item.style.color="red"));
  4. //console.log(([...ul.children].shift().style.color="blue"));
  5. console.log((ul.firstElementChild.style.color="blue"));
  6. console.log(ul.lastElementChild.style.color="blue");
  7. //第二个元素
  8. console.log(ul.firstElementChild.nextElementSibling.style.color="red");
  9. //第四个元素
  10. console.log(ul.lastElementChild.previousElementSibling.style.color="blue");
  11. //第三个元素
  12. const li =document.querySelector(".item:nth-of-type(3)");
  13. console.log(li);

//创建只在内存中,不在页面中 creeateElement
let div=document.createElement(“div”);
let p =document.createElement(‘p’);
p.textContent=”Hello World”;
//将元素渲染到页面中
document.body.append(p);
console.log(document.querySelector(‘div’).id);
console.log(document.querySelector(‘div’).data-email);
对于这样的自定义属性,成为数据属性
console.log(document.querySelector(“div”)[“data-email”]);
//dataset专用获取’data-前缀的自定义’
let email2=document.querySelector(“div”).dataset.email;
let email1=document.querySelector(“div”).dataset.email;
console.log(email2);
console.log(email1);
</script>

```

Correcting teacher:PHPzPHPz

Correction status:unqualified

Teacher's comments:还是markdown语法的问题,如果不知道怎么使用,可以找助教
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