鼠标移动到div上时,获取事件对象event、容器id、鼠标的位置


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Titletitle>
    <script src="../js/jquery-3.3.1.min.js" type="text/javascript">script>
head>
<body style="display: flex;">
    <div id="div1" class="item" style="width: 300px;height: 300px;border: red solid 1px;">div>
    <div id="div2" class="item" style="width: 300px;height: 300px;border: red solid 1px;">div>
    <div id="div3" class="item" style="width: 300px;height: 300px;border: red solid 1px;">div>
    <script>
        $('.item').mouseover(function(event){
            console.log(event);                 //获取事件对象
            console.log(event.target.id);       //获取容器id
            console.log(event.pageX);           //获取鼠标位置:x坐标
            console.log(event.pageY);           //获取鼠标位置:y坐标
        });
    script>
body>
html>

你可能感兴趣的:(jquery)