首页 > Web开发 > 详细

html5 选择元素

时间:2016-12-31 21:54:43      阅读:214      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
    .div1{width: 50px; height: 50px; background: yellow;}
    .div2{width: 50px; height: 50px; background: red; }
    </style>
    <script>
        window.onload=function(){
            /*只能获取元素 的第一个*/
         var odiv=document.querySelector(‘.div1‘);
          var oall=document.querySelectorAll(‘div‘);
         odiv.style.background="red";
         
         oall[1].style.height=‘1000px‘;

         var odiv3=document.getElementById(‘div3‘);
         /*类似于数组的对象*/
         alert(odiv3.classList);

         odiv3.classList.add(‘box7‘);
         odiv3.classList.remove(‘box3‘);
         odiv3.classList.toggle(‘box4‘);

         
        }
    </script>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
<div id="div3" class="div3 div4 div5"></div>
    
</body>
</html>

 

html5 选择元素

原文:http://www.cnblogs.com/hack-ing/p/6240241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!