样式操作-核心DOM
1.核心DOM
只能操作行内(内嵌)样式-->style里面的所有内容(核心DOM)
//麻烦获取
console.log(div.getAttribute("style"));//只能获取html属性
div.setAttribute("style","border:10px solid blue;");//替换
//麻烦设置 div.setAttribute("style","height:200px;width:300px;border:10px solid blue;");//要想修改,需要全部重写
2.HTML DOM
只能操作行内(内嵌)样式-->style里面的单个属性(HTML DOM)
//简单行内获取
console.log(div.style.border);
//简单行内设置
div.style.border="10px solid blue";
//获取 所有方法样式(兼容)
if(div.currentStyle){
console.log(div.currentStyle.color);//IE
console.log(div.currentStyle.fontSize);//IE
}else{
console.log(getComputedStyle(div).color);//ff
console.log(getComputedStyle(div).fontSize);//ff
}
//设置 所有方法样式--->只能设置内嵌 内嵌>内部和外部
div.style.color="pink";

浙公网安备 33010602011771号