##


6
0
0
思如磐石
思如磐石

reply all (5)
ganhuihui
   


    ganhuihui
    #test1 { width:300px; height:300px;


    • reply <!DOCTYPE html> <html> <head> </head> <style> #test1 { width:300px; height:300px; background-color:blue; } </style> <body> <div id="test1"></div> </body> <script> function test1() { var a = document.getElementById('test1'); var finalStyle = a.currentStyle ? a.currentStyle : document.defaultView.getComputedStyle(a, null);/*Use to determine whether currentStyle is supported (whether it is ie) 13. Get style through different methods*/ if(finalStyle.backgroundColor=="rgb(0, 0, 255)"){ a.style.backgroundColor="red"; } else if(finalStyle.backgroundColor=="rgb(255, 0, 0)"){ a.style.backgroundColor="blue"; } } function addEvent(obj,type,handle){ try{ // Chrome, FireFox, Opera, Safari, IE9.0 and above obj.addEventListener(type,handle,false); }catch(e){ try{ // IE8.0 and below obj.attachEvent('on' + type,handle); }catch(e){ // Early browsers obj['on' + type] = handle; } } } window.onload = function(){ var element = document.getElementById("test1"); addEvent(element,"click",test1); } </script> </html>
      ***huihui author 2018-01-18 14:31:01
    有人@我
    1. You can use addinventlisner() to listen for click events, initialize it to red, change it to blue when you click it for the first time, and then turn it to red when you click it again

    2. ##Preparation A class{background-color:#f00}, when you click it, add a class name to it, and when you click it again, let it remove the class name

    3. You can use move in Remove event


      p~ang~胖

      A is undefined when executed for the second time. Just put var a = document.getElementById('test1'); outside the function

        dabour

        Shouldn’t just change one ID, if the match is successful, another one will be displayed

          Popular Topics
          More>
          Popular Articles
          Popular Tutorials
          More>
          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!