相关文章推荐
活泼的硬盘  ·  國立中山大學,National Sun ...·  4 月前    · 
慷慨大方的皮带  ·  vue3+ts:shims-vue.d.ts ...·  1 年前    · 
失落的勺子  ·  Java AWS S3 ...·  1 年前    · 
开心的刺猬  ·  日期时间格式化_时间格式 占位-CSDN博客·  2 年前    · 
年轻有为的橡皮擦  ·  Python把嵌套的字符串列表转换为整数列表 ...·  3 年前    · 
急躁的数据线  ·  程序运行慢?你怕是写的假 ...·  3 年前    · 
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>
 
推荐文章
活泼的硬盘  ·  國立中山大學,National Sun Yat-sen University,學位論文,thesis/dissertation,應用於CRYSTALS-Kyber之AES與SHA-3加速電路設計,Ef
4 月前
慷慨大方的皮带  ·  vue3+ts:shims-vue.d.ts-CSDN博客
1 年前
失落的勺子  ·  Java AWS S3 文件上传实现_aws-java-sdk-s3-CSDN博客
1 年前
开心的刺猬  ·  日期时间格式化_时间格式 占位-CSDN博客
2 年前
年轻有为的橡皮擦  ·  Python把嵌套的字符串列表转换为整数列表的两种方法_51CTO博客_python嵌套列表输出
3 年前
急躁的数据线  ·  程序运行慢?你怕是写的假 Python-python运行速度慢
3 年前
今天看啥   ·   Py中国   ·   codingpro   ·   小百科   ·   link之家   ·   卧龙AI搜索
删除内容请联系邮箱 2879853325@qq.com
Code - 代码工具平台
© 2024 ~ 沪ICP备11025650号