批改状态:合格
老师批语:
1.while循环语句组成:
()里面{}大括号内while和判断条件在循环体前面,而出口判断指循环体前面加do关键,而while和判断条件在循环体后2.for循环语句组成
()里面{}大括号内1.每一个函数都有一个原型属性:prototype,但原型属性对普通函数没有,对构造函数来数才有用
2.构造函数是“对象工厂”,用来创造对象(对象也叫实例)
3.js中没有‘类’的概念,它是基于原型的语言,所以简单的将构造函数当成类
4.构造函数必须通过“new”来调用,new的过程就是类实例化的过程
5.构造函数的名称一般首字母大写作为区分
6.构造函数中this用来代替构造函数的函数创建对象的本身
7.构造函数原型prototype和对象实例原型__proto__,需要被所有类实例共享的成员,应该写到构造函数的原型上;
1.类的组成:
class{}constructor(){}static 静态方法可以通过类名直接调用ES6中的类内部没有静态属性,只有静态方法,通过类直接添加的属性等同于静态属性#,私有变量外部无法直接访问,可以通过访问器属性访问set和get 主要用于访问对象的私有属性extendssuper函数继承,解决字类无法访问父类属性。1.选中元素(DOM):
-document.querySelector();选中匹配的第一个并返回
Element.insertAdjacentHTML(“where”,元素):按位置要求插入元素;
beforeBegin: 插入到标签开始前
afterBegin:插入到标签开始标记之后
beforeEnd:插入到标签结束标记前
afterEnd:插入到标签结束标记后
new Document.Fragment(),把要出入的元素挂载到片段上,以此性插入
<!DOCTYPE html><html lang="zh"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title></title></head><body><ul><li>item1</li><li>item2</li><li id="three">item3</li><li>item4</li><li>item5</li></ul></body><script type="text/javascript">let lis=document.querySelectorAll("ul > li");let lis1=document.getElementsByTagName("li");console.log(lis1);// for(let i of lis){// console.log(i);// }for(let i in lis1){console.log(i);}// 构造函数let User=function (name,age){this.name=name;this.age=age;}let user=new User('ldy',30);console.log(user.name);console.log(user.age);console.dir(user);console.dir(User);user.__proto__.sex="男";console.log(user.sex);// ES6 :类class UserName {// static sex="男";constructor(name,age){this.name=name;this.age=age;// this.sex=sex;}show(sex){return `${this.name},${this.age},${sex},${this.sex}`;}}UserName.sex="男";let username=new UserName("ldy",30);console.log(username.show(UserName.sex));class User1 extends UserName{constructor(name,age,sex){super(name,age);this.sex=sex;}}let user1= new User1("dlf",25,"nv");console.log(user1.show("女"))let ul=document.querySelector('ul');console.log(ul);let item=document.createElement("li");item.innerText="item.item";item2=`<li style="color:red">item*3</li>`// ul.appendChild(item);//在后面追加元素;ul.insertAdjacentHTML('afterBegin',item2);ul.replaceChild(item,document.querySelector("#three"));ul.removeChild(document.querySelector("ul> li:first-child"));console.log(document.querySelector("li:nth-child(2)").previousElementSibling);</script></html>
演示结果:
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号