相关文章推荐
内向的脸盆  ·  蜂巢能源子公司章鱼博士荣获“CFS第十三届财 ...·  2 月前    · 
睡不着的楼房  ·  spring.main.allow-bean ...·  2 月前    · 
气宇轩昂的葫芦  ·  python 图像对比度计算-掘金·  2 年前    · 
俊秀的瀑布  ·  富文本编辑器 quill.js ...·  2 年前    · 
逼格高的小虾米  ·  How to disable ...·  2 年前    · 
Code  ›  JS示例01-鼠标移入移出事件开发者社区
js 软件 信息安全
https://cloud.tencent.com/developer/article/1534375
粗眉毛的镜子
2 年前
作者头像
专注APP开发
0 篇文章

JS示例01-鼠标移入移出事件

前往专栏
腾讯云
开发者社区
文档 意见反馈 控制台
首页
学习
活动
专区
工具
TVP
文章/答案/技术大牛
发布
首页
学习
活动
专区
工具
TVP
返回腾讯云官网
社区首页 > 专栏 > 移动大前端 > JS示例01-鼠标移入移出事件

JS示例01-鼠标移入移出事件

作者头像
专注APP开发
发布 于 2019-11-07 15:27:30
3.4K 0
发布 于 2019-11-07 15:27:30
举报

一、知识要点

1、匿名函数 2、鼠标事件 3、document.getElementById() 4、window.onload 5、行间事件提取

二、源码参考

<!DOCTYPE >
        <title></title>
        <meta charset="utf-8">
        <style>
            #div1 {
                width: 200px;
                height: 100px;
                background-color: #ccc;
                border: 1px solid #999;
                display: none;
        </style>
        <script>
            window.onload = function() {
                var input1 = document.getElementById('input1');
                var div1 = document.getElementById('div1');
                input1.onmouseover = function() {
                    div1.style.display = 'block';
                input1.onmouseout = function() {
                    div1.style.display = 'none';
        </script>
    </head>
        <input id="input1" type="checkbox" value="checkbox" />
        <div id="div1">
            为了您的信息安全...
    </body>
</html>

三、运行效果

image

分享隐藏显示

<!DOCTYPE HTML>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
        #div1 {
            width: 100px;
            height: 200px;
            background: red;
            position: absolute;
            left: -100px;
            top: 100px;
        #div2 {
            width: 30px;
            height: 60px;
            position: absolute;
            right: -30px;
            top: 70px;
            background: black;
            color: white;
            text-align: center;
    </style>
    <script>
        window.onload = function () {
            var oDiv = document.getElementById('div1');
            oDiv.onmouseover = function () {
                this.style.left = '0px';
            oDiv.onmouseout = function () {
                this.style.left = '-100px';
    </script>
</head>
 
推荐文章
内向的脸盆  ·  蜂巢能源子公司章鱼博士荣获“CFS第十三届财经峰会-2024科技创新引领奖”_中华网
2 月前
睡不着的楼房  ·  spring.main.allow-bean-definition-overriding=true是个不好的做法吗?-腾讯云开发者社区-腾讯云
2 月前
气宇轩昂的葫芦  ·  python 图像对比度计算-掘金
2 年前
俊秀的瀑布  ·  富文本编辑器 quill.js 开发(五): 自定义插件 - Grewer - 博客园
2 年前
逼格高的小虾米  ·  How to disable ondblclick in JavaScript? - Stack Overflow
2 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号