dom添加样式可以这样写

原生 js添加样式很多时可以合并在一起写:

var oPopwin = document.getElementById('vpage');
oPopwin.style.margin = 'initial';
oPopwin.style.marginTop = 'initial';
oPopwin.style.bottom = "0"
oPopwin.style.right = "0"

可以这样写简化代码:

var oPopwin = document.getElementById('vpage');
oPopwin.style ='margin:initial;marginTop:initial;bottom:0;right:0;'

HTML DOM classList 属性

可添加、删除一个或多个class

document.getElementById('div1').classList.add('add1','add2','add3')
document.getElementById(
"div1").classList.remove("add1",'add3')

猜你喜欢

转载自www.cnblogs.com/liubingyjui/p/12753647.html