javascript点击切换背景颜色和背景大小

css

<style>
         .box{
             width: 800px;
             height: 600px;
             border: 1px solid gray;
             position: relative;
         }
         #wod{
             width: 200px;
             height: 200px;
             background-color: blue;
         }
         #content{
             position: absolute;
             top: 0;
             right: 0;
             width: 180px;
             height: 400px;
             background-color: aqua;
             border: 1px solid gray;
             display: none;
             text-align: center;
             float: right;
         }
         .yang{
             width: 80px;
             height: 20px;
             background-color: white;
             border: 1px solid gray;
             margin: 0 auto;
             margin-top: 20px;
             margin-bottom: 10px;
         }
         #bbt{
             position: absolute;
             top: 0;
             right: 0;
             font-size: 20px;
         }
        
    </style>


<body>
    <div class="box">
        <input type="button" id="bbt" value="点击显示div样式">
        <div id="wod">
                <div id="content">
                        <h2>大小</h2>
                        <p class="yang" id="ou">100*100</p>
                        <p class="yang" id="oy">200*200</p>
                        <h2>颜色</h2>
                        <p class="yang" id="oz">#ff0000</p>
                        <p class="yang" id="ol">#00ff00</p>
                        <input type="button" id="qr" value="确认">
                        <input type="button" id="qx" value="取消">
                    </div>
                </div>
            </div>
</body>


<script type="text/javascript">
    var bbt = document.getElementById('bbt');
    bbt.onclick = function(){
       content.style.display = "block";
      
    }
    var content = document.getElementById('content');
    
  var ou = document.getElementById('ou')
  ou.onclick = function(){
     wod.style.width = "200px";
     wod.style.height = "400px";
  }

 
  var qr = document.getElementById('qr');
  qr.onclick = function(){
       content.style.display='none';
    }
  var qx = document.getElementById('qx');
     qx.onclick = function(){
        wod.style.width='1px';
     }

 var oy = document.getElementById('oy')
  oy.onclick = function(){
     wod.style.width = "300px";
     wod.style.height = "300px";
    

  }
  var oz = document.getElementById('oz')
  oz.onclick = function(){
     
     wod.style.backgroundColor = "yellow";

  }
  var ol = document.getElementById('ol');
  ol.onclick = function(){
    
     wod.style.backgroundColor = "pink";

  }




   
</script>

在这里插入图片描述

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值