1、修改樣式:訪問內聯樣式:elem.style.css屬性名;獲得其他:var style=getComputerStyle(elem);*(* 獲得焦點onfocus;失去焦點onblur;); 2、修改內外部樣式屬性:①獲得樣式表對象:var sheet=document.styleSheet ...
1、修改樣式:訪問內聯樣式:elem.style.css屬性名;獲得其他:var style=getComputerStyle(elem);*(* 獲得焦點onfocus;失去焦點onblur;);
2、修改內外部樣式屬性:①獲得樣式表對象:var sheet=document.styleSheets【i】;②獲得cssRule對象:var rule=sheet.cssRules【i】;③修改cssRule屬性:rule.style.css屬性名=值;
3、添加:①創建空元素對象:var a=document.createElement(“a”);②設置元素相關屬性:a.href=“http://xxx.com”;a.innerHTML=“跳轉到XXX”;③將元素掛到指定父元素下:a、末尾追加:parent.appendChild(a);b、插入:parent.insertBefore(a,舊元素);c、替換:parent.replaceChild(a,舊元素);
4、文檔片段:①創建文檔片段:var frag=document.createDocumentFragment();②將平級子元素追加到frag下;③將文檔片段整體添加到頁面;
5、刪除:①parent.removeChild(child);②child.parentNode.remove(child);
6、HTML DOM常用對象之Image:創建:var img=new Image();
7、HTML DOM常用對象之Select:屬性:①selectedIndex:當前選中項的下標;②options:獲得select下所有option元素的集合;創建:var opt=new Option(text,value);《==》var opt=document.createElement(“option”);opt.innerHTML=text;opt.value=value;③add(option):向select追加option對象;appendChild(option);④remove(i):移除select下i位置的option;⑤事件:onchange:當選中項發生改變時觸發;