CSS DOM dynamic style
Use JS to operate each attribute in CSS.
JS can only operate or modify inline styles. For example: imgObj.style.border = “1px solid red”
For class styles, assign values through className. For example: imgObj.className = “imgClass”
##style object
##Conversion between style object attributes and CSS attributes
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> //网页加载完成 window.onload = init; function init() { //获取id=img01的图片对象 var imgObj = document.getElementById("img1"); //给<img>标记添加行内样式 imgObj.style.width = "400px"; imgObj.style.border = "2px solid red"; imgObj.style.padding = "20px 30px"; imgObj.style.backgroundColor = "#f0f0f0"; } </script> </head> <body > <img id="img1" src="/upload/course/000/000/009/580af7f52278b486.jpg" /> </body> </html>Next Section