javascript冒泡事件代码

来源:互联网 发布:淘宝上哪些店银是真的 编辑:程序博客网 时间:2024/05/23 11:22

1:在html中创建两个div

<div id="diva">        <div id="divb">啦啦啦</div>    </div>

2:在css中写div的样式:

  #diva{            width: 200px;            height: 300px;            background: greenyellow;            position: absolute;           margin-left: 300px;        }        #divb{            width: 100px;            height: 20px;            background: pink;            position: absolute;            color: blueviolet;            margin-top: 300px;            margin-left: 50px;        }

3:在JavaScript中写点击事件:

  <script>        var oDiv = document.getElementById("diva");        oDiv.onmouseover = function(){            this.style.top ="0px";        }        oDiv.onmouseout=function(){            this.style.top="-300px";        }    </script>

4:在浏览器中运行。


0 0
原创粉丝点击