首页 > Web开发 > 详细

js操作元素的样式

时间:2019-10-02 17:47:13      阅读:123      评论:0      收藏:0      [点我收藏+]

1.元素.style.属性=‘属性值‘

var div=document.getElementById(box)
div.style.width=300px;
div.style.height=300px;
div.style.backgroundColor=red;   //css中有-的属性,在js中要改成驼峰命名法

2.div.style.属性     获取元素的样式

var div=document.getElementById(box)
console.log(div.style.width);
console.log(div.style.height);
console.log(div.style.backgroundColor);   //如果要通过style获取样式,只能获取行内样式

3.通过操作类,改变元素的样式

var div=document.getElementById(box)
div.className +=  one//一定要记得+空格

 

js操作元素的样式

原文:https://www.cnblogs.com/zhaodz/p/11617779.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!