java学习

java学习

 

javascript操作css

javascript操作css中,如果css的属性是比如background-color中间有横线的,在javascript操作是要遵守驼峰命名法,如mydiv.style.backgroundColor='blue';

在点击让图片显示和隐藏时cssstyle.visibility=hidden,让图片隐藏但是不释放空间,style.display=none,图片隐藏并且释放空间,style.display=block,图片显示,style.visibility=visible,图片显示。
一个定时不断改变颜色的例子:
<html>
 <head>
  <style type="text/css" >
   #mydiv{
    width:100px;
    height:100px;
   }
  </style>
  
 </head>
 <body>
 
  <div id="mydiv" ></div>
  <input id="start" type="button"  value="start" onclick="start()"/>
  <input id="end" type="button"  value="end" onclick="end()"/>
  <script type="text/javascript">
   
   var count = 4;
   var now = 1;
   function changea(){
    var mydiv = document.getElementById('mydiv');
    if(now==1){
     mydiv.style.backgroundColor='blue';
    }
    if(now==2){
     mydiv.style.backgroundColor='red';
    }
    if(now==3){
     mydiv.style.backgroundColor='black';
    }
    if(now==4){
     mydiv.style.backgroundColor='yellow';
    }
    now++;
   // alert(now);
    if(now>=5){
     now=1;
    }
    var a =setTimeout(changea,1000);
    
   }
   changea();
  </script>
 </body>
</html>

posted on 2013-06-26 16:08 杨军威 阅读(271) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜