首页 > 代码库 > 1_行为与样式分离

1_行为与样式分离

HTML代码:

1 <div id="box"></div>

CSS代码:

1 #box{ width:100px; height:100px; background:#99C;}

JS代码:

 1 window.onload=function(){ 2     var one=document.getElementById(‘box‘); 3     one.onmouseover=toRed; 4     one.onmouseout=toBlue; 5     } 6 function toRed(){ 7     var oDiv=document.getElementById(‘box‘); 8     two.style.width="200px"; 9     two.style.height="200px";10     two.style.background="red";}11 function toBlue(){12     var oDiv=document.getElementById(‘box‘);13     two.style.width="100px";14     two.style.height="100px";15     two.style.background="#99c";}

 

1_行为与样式分离