1、第一种:用cssText
div.style.cssText=‘width:600px;height:250px;border:1px red solid;text-align: center;line-height: 250px;’;
2、第二种:用setProperty()
div.style.setProperty(‘width’,‘700px’);
3、第三种:使用css属性对应的style属性
div.style.textAlign = “center”;
2020-3-27原生JS/ZL2:js改变css样式的三种方法
猜你喜欢
转载自blog.csdn.net/qq_25787687/article/details/105143671
今日推荐
周排行