批改状态:合格
老师批语:
// *一.纯数组const city=['beijing','shanghai','guangzhou'];console.log(city);// *判断数组是否是对象console.log(city instanceof Object);// *观察这种数组有两个特点:// *1.每个值对应一个键名(也叫索引),是从0,1,2,3,...// *2.有一个length属性,叫数组长度// *3.这种数组叫纯数组或叫真数组// *二.模仿数组的形式创建一对象:类数组:const student={0:'name1',1:'age',2:'sex',length:3,};console.log(student);// *以上两种形式都很相似,而区别就是:一种是数组构造器,另一种是对象构造器// *这样的对象数组就称为类数组,其实就是一个对象字面量。// *类数组的意思就是很相似数组,但其实不是数组

// *获取dom元素有两种方式:// *1.获取一组dom元素:// *用querySelectorAll()方式,返回类数组const list=document.querySelectorAll('.menu .title');console.log(list);// *2.获取一个dom元素// *用querySelector()方式,返回一个dom元素// *取第一个元素const first=document.querySelector('.menu .title');console.log(first);first.style.backgroundColor='red';

// *用较为优雅简洁的方式获取表单元素及其控件的值:// *获取表单console.log(document.forms.login);// *获取控件邮箱console.log(document.forms.login.email);// *获取控件邮箱的值console.log(document.forms.login.email.value);// *获取控件密码console.log(document.forms.login.password);// *获取控件密码的值console.log(document.forms.login.password.value);

let ul=document.querySelector('.gz');// *返回元素节点(类数组)console.log(ul.children);// *将类数组转为真数组的方法console.log([...ul.children]);// *设置第一个元素背景色ul.firstElementChild.style.backgroundColor='red';// *第二个ul.firstElementChild.nextElementSibling.style.backgroundColor='green';// *最后一个ul.lastElementChild.style.backgroundColor='lightblue';// *倒数第二个ul.lastElementChild.previousElementSibling.style.backgroundColor='lightgreen';// *为父节点加边框ul.lastElementChild.parentElement.style.border='2px solid red';

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号