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

jqueryweb developmentfront end technology

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

示例

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/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>

相关文章