美文网首页
jQuery事件

jQuery事件

作者: 孙子衡 | 来源:发表于2018-09-21 20:35 被阅读0次

事件的三种加载方式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        #div01{
            width: 300px;
            height: 330px;
            background-color: #01AAED;

        }

    </style>

</head>
<body>

<div id="div01" ></div>

<div id="div02" onclick="divClick(this);" ></div>


<script src="../jquery-3.3.1.min.js"></script>
<script>

    var div01 = document.getElementById('div01');

    // 第一种写法
//    div01.onclick = function () {
//        alert(222);
//    }

     第二种写法
    function divClick(obj) {

        obj.style.background = 'yellow';
    }

    // 第三种写的
    div01.addEventListener('click',function () {
        this.style.background = 'yellow';
    })


</script>

</body>
</html>

事件

event description
onclick 鼠标点击
ondblclick 鼠标双击
oncontextmenu 鼠标右击
onmouseover 鼠标移入
onmouseout 鼠标移出
onmousemove 鼠标移动
onmousedown 鼠标按下
onmouseup 鼠标抬起

实例代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>

        *{
            margin: 0;
            padding: 0;
        }
        .div01{
            width: 300px;
            height: 300px;
            background-color: #5bc0de;
        }


    </style>
</head>
<body>

<div class="div01">
    我事件测试的div
</div>

<script src="../jquery-3.3.1.min.js"></script>




<script>
    var div = document.getElementsByClassName('div01');
    console.log(div);

    /*
    div[0].onclick = function () {
        console.log('我被点击了.........');
    }

    div[0].ondblclick = function () {
        console.log('我被双击了.........');
    }

    div[0].oncontextmenu = function () {
        console.log('我被右击了..........');
    }

    div[0].onmouseover = function () {
        console.log('我是鼠标移入........');
    }

    div[0].onmouseout = function () {
        console.log('我是鼠标移出..........');
    }

    div[0].onmousemove = function () {
        console.log('我是鼠标移动.......');
    }

    div[0].onmousedown = function () {
        console.log('我被按下了.........')
    }

    div[0].onmouseup = function () {
        console.log('我被抬起了...........')
    }
    */
    div[0].onmousemove = function (e) {
        // js中会自动将事件对象赋值给形参 e
        console.log(e);
        // e.vlientX : 鼠标距离屏幕左上角的水平距离
        // e.pageX : 鼠标距离文档左上角的值
        console.log(e.clientX,e.clientY,e.pageX,e.pageY);

        // offsetWith = border + padding + width
        console.log(this.offsetWidth,this.offsetHeight);
        // offsetTop : 参考对象是里他最近的参考对象如果没有 默认是 body
        console.log(this.offsetTop,this.offsetLeft);


    }

</script>

</body>
</html>

相关文章

  • jquery实战

    jQuery属性操作 jQuery特殊效果 jQuery动画 jQuery循环 jQuery其他事件 自定义事件

  • jQuery知识整理

    jQuery jQuery和DOM关系 jquery框架对象分析 加载事件 事件绑定 动画效果 jquery封装的...

  • jqurey事件

    jQuery 事件函数 jQuery 事件处理方法是 jQuery 中的核心函数。 事件处理程序指的是当 HTML...

  • jQuery基础(三)—事件篇-----鼠标事件

    jQuery鼠标事件之click与dbclick事件jQuery鼠标事件之mouseover与mouseout事件...

  • jQuery动画、循环、事件

    jQuery动画 jQuery循环 元素绝对位置 鼠标移入移出 jQuery事件 自定义事件 事件冒泡 弹框-阻止冒泡

  • Jquery day_3

    1.1 Jquery 事件注册 1.2 jquery 事件处理 on(): 用于事件绑定,目前最好用的事件绑定方...

  • jQuery事件操作和插件

    jQuery事件操作 简单方式注册事件 语法:jQuery对象.事件名(事件处理程序) on方法注册事件 注册简单...

  • jquery对节点的操作

    Jquery对事件的绑定 $().bind(“事件类型”, 事件处理); 给jquery绑定一个事件$().bi...

  • jQuery事件机制

    jQuery的事件机制,指的是:jQuery对JavaScript操作DOM事件的封装,包括了:事件绑定、事件解绑...

  • jquery 滚轮插件 jquery.mousewheel.js

    jquery.mousewheel插件使用 jquery中没有鼠标滚轮事件,那么可以使用jquery的滚轮事件插件...

网友评论

      本文标题:jQuery事件

      本文链接:https://www.haomeiwen.com/subject/wmymnftx.html