12345678910111213141516171819202122232425262728293031323334 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- #div1{
- width: 200px;
- height: 200px;
- background: aqua;
- left: 300px;
- top: 50px;
- position: absolute;
- }
- </style>
- </head>
- <body>
- <div id="div1"></div>
- <button class="btn">变换位置</button>
- <script>
- var div1 = document.getElementById('div1')
- var btn = document.getElementsByClassName('btn')
- btn[0].onclick = function(){
- // console.log(111)
- div1.style.left = 700 + 'px'
- div1.style.top = '200px'
- div1.style.background = 'red'
- }
- </script>
- </body>
- </html>
|