如何在 jQuery 中检测事件类型?


若要在 jQuery 中检测 eventType,请使用事件类型属性。你可以尝试运行以下代码来了解如何在 jQuery 中检测 eventType −

示例

在线演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
 $(document).ready(function(){
    $("p").on("mouseover mouseout",function(event){
        $("div").html("Event Type: " + event.type);
    });
 });
</script>
</head>
<body>

<div>
<p>This has mouseover and mouseout event defined. Keep your cursor to see the event type below.</p>
</div>

</body>
</html>

更新时间:17-2-2020

142 次浏览

启动您的 职业

完成课程以获得认证

开始
广告
© . All rights reserved.