js如何控制css

js如何控制css

1、直接设置Style对象:

el.style.color = '#b50029';
el.style.fontSize = '30px';
el.style['font-size'] = '30px';

2、设置style属性:

el.setAttribute('style', 'color: red;');
el.setAttribute('style', 'font-size: 30px');
el.setAttribute('style', 'font-size: 30px');
el.setAttribute('style', 
'color: red;' + 'font-size: 30px;' + 'background-color: green');

3、设置cssText(相关课程推荐:JS视频教程

el.style.cssText = "color: red;font-size: 30px";
el.style.cssText = "color: red;font-size: 30px";
el.style.cssText += 'background-color: yellow';
el.style.cssText = "color: red;font-size: 30px";
el.style.cssText += 'background-color: yellow'; 
el.style.cssText = "text-decoration: line-through";

4、改变class类名 

el.className = 'cNone';
el.className += 'cNtwo'; >> el[class="cNone cNtwo"]
el.className = 'cNone';
el.className = 'cNtwo';      >>el[class="cNtwo"]

更多JavaScript相关技术文章,请访问JavaScript答疑栏目进行学习!

以上就是js如何控制css的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 答疑