ITeye博客

动态样式

sric08 · 2011-04-18 15:11 · Web前端 · HTML · CSS · .net · Microsoft · JavaScript · Markdown

这是某种实现方式

 

<html>
	<head>
		<title></title>
		<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
		<style type="text/css" id="a">
.hello {
	background-color: pink;
}
</style>
		<style type="text/css">
.world {
	color: #33FF99
}
</style>
		<script language="javascript">
  var turnback=false;
  function setCSS()
  {
  	var ttt = document.getElementById("ttt");
  	if(turnback){
		a.styleSheet.cssText=".hello{background-color:pink;width:"+ttt.value+"px;height:"+ttt.value+"px}";
	}else{
		a.styleSheet.cssText=".hello{background-color:gray;width:"+ttt.value+"px;height:"+ttt.value+"px}";
	} turnback=!turnback;
  }
  </script>
	</head>
	<body>
		<input type="text" id="ttt">
		<button onclick="setCSS()" type="button">
			切换背景颜色
		</button>
		<div class="hello world">
			hello world
		</div>
		<div class="hello world">
			hello world
		</div>
		<div class="hello world">
			hello world
		</div>
		<div class="hello world">
			hello world
		</div>
	</body>
</html>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。