<html>
<head>
<style>
#round{
width:300px
height:200px
}
</style>
</head>
<script>
var oDiv = document.getElementById('round')
oDiv.style.width = 400px //通过js改变这个div的宽度
</script>
<body>
<div id='round'>
<p>我是测试文字</p>
</div>
</body>
</html>
原型是用DOM的style属性方法:
Element.style.[styleDOMName] = "value"Element:指定元素,用document.createElement / document.getElement获取元素obj
或者使用setAttribute方法:
Element.setAttribute('style','css代码')//会覆盖所有的原来在这个标签上style属性赋的值Element.setAttribute('style',Element.getAttribute('style') + "")//不会覆盖
1、使用obj.className来修改样式表的类名。2、使用obj.style.cssTest来修改嵌入式的css。
3、使用obj.className来修改样式表的类名。
4、使用更改外联的css文件,从而改变元素的css