DOM

# dom对象 #
<h6>1.属性:document.title 返回一个标题<h6>


    例如: window.οnlοad=function(){  
             console.log(document.title);  
             document.title="123456";  
         }      
 2.属性:document.URL 返回一个完整的URL;
   
   例如:window.οnlοad=function(){  
           console.log(document.url);  
            document.url="1.html"
  
}  
 3.属性:document.bgColor:背景色 
 
   例如:window.οnlοad=function(){  
             console.log(document.bgColor);  
             document.bgColor="red";  
         }   
 4.属性:FGCOLOR:前景色;  
    例如:  
           window.οnlοad=function(){    
             console.log(document.fgColor);    
             document.bgColor="green";  
二、对象集合:  
   1.表单 : 
    在浏览器下找到表单里面的name和它对应的值  
     例如:  
       window.οnlοad=function(){  
           var form1=document.getElementById("form1");  
           console.log(document.form1.name11[0].value);  
       };  
   2.通过下标获取表单的元素;  
  
     例如: <script>  
           window.οnlοad=function(){  
           var form1=document.getElementById("form1");  
           console.log(document.form1.name11[0].value);  
       }; //获取表单1 id为name11,的值   
          console.log(document.[form1]) //获取form信息  
           console.log(document.forms.length);获取表单个数 
          </script>
          <body>  
           <form id="form1" name="form1">  
   <input  type="text" name="name11" value="11">  
   <input  type="text" name="name11" value="11">
   <input  type="text" name="name11" value="11">
   <input  type="text" name="name11" value="11">


          </form>


          </body>
   3.属性操作:利用JS改变元素的属性;  
         
     例如:
         
         <script>
          window.οnlοad=function(){
          var a1=document.getElementById("a1");
          a1.style.width="100px";
          a1.style.height="100px";
          a1.style.backgroundColor="red";
          a1.style.boder="1px,solid";
         a1.style.color="green";
         a1.style.textAlign="center";
         a1.style.display="block";
         a1.style.lineHeight="100px";
         a1.style.fontSize="30px";
         a1.style.textDecoration="none";
          </script>
     BODY:<a id="a1"href="#">111111</a>
    
  4.伪类:  
      例如: 例如:
         
         <script>
          window.οnlοad=function(){
          var a1=document.getElementById("a1");
          a1.style.width="100px";
          a1.style.height="100px";
          a1.style.backgroundColor="red";
          a1.style.boder="1px,solid";
         a1.style.color="green";
         a1.style.textAlign="center";
         a1.style.display="block";
         a1.style.lineHeight="100px";
         a1.style.fontSize="30px";
         a1.style.textDecoration="none";  


             a1.οnmοuseοver=function(){
             this.style.backgroundColor="gray";
             this.style.color="pink";


         };




         a1.οnmοuseοut=function(){
             this.style.backgroundColor="red";
         };
          </script>
     BODY:<a id="a1"href="#">111111</a>   
  5.叠层样式表:  
  
    例如: <script>
            function getBackgroundColor(){
                var oCSSRules=document.styleSheets[0].cssRules||
                document.styleSheets[0].rules;
                console.log(oCSSRules[0].style.backgroundColor);


            }
      
          </script> 
         <body>
 <div id="div1" class="special"></div>
<input type="button" value="得到背景色" οnclick="getBackgroundColor()"/>
         </body>
     


  6.获取元素尺寸:如果有padding值就+  
    例如:  
    CSS{ #one{width: 200px;  
            height: 100px;  
            background: red;  
            padding: 10px;}}   


     <script>
     window.οnlοad=function(){
        var one=document.getElementById("one");
        console.log(one.clientWidth+""+one.clientHeight);
        console.log(one.offsetHeight+""+one.offsetWidth);
    }
    </script>
  
    <div id="one"></div>
 7.最终样式:
    例如:
     css: #one{width: 100px;  
            height: 100px;  
        background: saddlebrown;}  
    <script>
              window.οnlοad=function(){
                var one=document.getElementById("one");
                //console.log(one.currentStyle.width);
                console.log(window.getComputedStyle(one, null).width)
    </script>
     <div id="one"></div>
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值