日期:2014-05-16  浏览次数:20373 次

<js>关于在.js内获取.css里属性
写脚本的时候需要获取main.css下
.ground_body{
background-image: url(../images/background/main.png);
background-repeat: no-repeat;
background-position: center;
background-size:567px;
}
里的 background-size:567px 的值,并想在h_1.js下修改。
h_1.js main.css 都是外部引用
上网查过,但是外部引用的没看懂写的。
不知道谁愿意教我一下,谢谢~

------解决方案--------------------
js里面修改?
方法1,
xx对象的.className="ground_body"

方法2:
xx对象的.style.backgroundSize="567px"
------解决方案--------------------
xxx.css
.test { width:10px; background-color: red; } 

js里面
	// 访问 styleSheet 中的一条规则, 将其 backgroundColor 改为蓝色。
  var oStyleSheet = document.styleSheets[0];
  var oRule = oStyleSheet.rules[0];
  oRule.style.backgroundColor = "#0000FF";

<div class="test">aaa</div> 

已测试。你可以把color改成size