函数
获取节点的方式:this
let oWrap = document.getElementById("wrap"); //不标准的写法 // oWrap.style = "width: 300px"; //style 这个合法的标签属性很特殊 console.log( oWrap.style ); oWrap.style.width = "300px"; oWrap.style.height = "200px"; oWrap.style.backgroundColor = "red"; //样式操做 let oWrap = document.getElementById("wrap"); oWrap.onclick = function(){ // oWrap.style.width = "500px"; //在事件函数里面,能够用 this来代替oWrap this.style.width = "500px"; }; //变相操做样式 let oWrap = document.getElementById("wrap"); oWrap.onclick = function(){ //添加名字,点击时,更换名字生成样式 this.className = "fly"; };