如何在 jQuery 中檢測事件型別?


若要在 jQuery 中檢測 eventType,請使用事件型別屬性。你可以嘗試執行以下程式碼來了解如何在 jQuery 中檢測 eventType −

示例

線上演示

<!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>

更新時間:17-2-2020

142 次瀏覽

啟動您的 職業

完成課程以獲得認證

開始
廣告
© . All rights reserved.