函數
獲取節點的方式: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"; };