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

ExtJS--10.1 Ext工具类 Ext.util.CSS
<!DOCTYPE html>
<html>
<head>
	<title>Ext.util.CSS</title>
	<meta name="content-type" content="text/html" charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="../extjs4/resources/css/ext-all.css">
	<script type="text/javascript" src="../extjs4/bootstrap.js"></script>
	<script type="text/javascript">
		Ext.onReady(function(){
			
/** 1. createStyleSheet( cssText, id ) : CSSStyleSheet */
			Ext.util.CSS.createStyleSheet(".c{color:red}","red");
			Ext.get("div01").addClsOnOver("c");
			
/** 2. getRule( selector, refreshCache ) : CSSStyleRule */
			var cssObj = Ext.util.CSS.getRule(".c",true);
			//alert(cssObj.style.color);
			
/** 3. swapStyleSheet( id, url ) */
			var i = 0 ;
			Ext.get("btn01").on("click",function(){
				if(i%3 == 0){
					Ext.util.CSS.swapStyleSheet("one","css/one.css");
				}else if(i%3 == 1){
					Ext.util.CSS.swapStyleSheet("two","css/two.css");
				}else if(i%3 == 2){
					Ext.util.CSS.swapStyleSheet("three","css/three.css");
				}
				Ext.get("div02").addClsOnOver("col");
				i++;
			});
			
/** 4. removeStyleSheet( id ) */
			Ext.get("btn02").on("click",function(){
				Ext.util.CSS.removeStyleSheet("red");
			}); 
			
/** 5. updateRule( selector, property, value ) */
			Ext.get("btn03").on("click",function(){
				Ext.util.CSS.updateRule(".c","color","#556677");
			});
		});
	</script>
</head>
<body>
	<div style="text-align: center;">
		<br><div id="div01">demo01</div>
		<br><div id="div02">demo02<input type="button" value="change" id="btn01"/></div>
		<br><div id="div03" class="c">demo03<input type="button" value="change" id="btn02"/></div>
		<br><div id="div04" class="c">demo04<input type="button" value="change" id="btn03"/></div>
	</div>
</body>
</html>

?