JavaScript操作元素与类.pdfVIP

  • 1
  • 0
  • 约小于1千字
  • 约 1页
  • 2026-07-28 发布于山西
  • 举报

操作元素样式

获得id名称是div1的对象

vardiv=document.getElementById(div1);

获得css样式只是支持行内样式的css

varwi=div.style.width;

varhi=div.style.height;

操作元素的css样式对于background-color格式的样

式在js中需要使用驼峰规则进行改变

div.style.width=300px;

div.style.height=300px;

div.style.backgroundColor=red;

通过操作类操作元素样式

通过增加class类来增加对应的css样式注意:className

div.className=div2;

文档评论(0)

1亿VIP精品文档

相关文档