新 jquery 库与旧脚本不兼容

New jquery library is not compatible with old script

嗨,我有这段代码:

$('li.dropdown-toggle').on('hover', function () {
    $(this).find(".submenu").slideToggle(200);
});

而且我注意到它在 jQuery 1.7.2 库下运行良好:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

但不低于 3.1.0

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

我可以在上面的代码中修改什么以使其在 3.1.0 下运行良好吗?我真的不想更改库,以防万一其他脚本停止工作。

谢谢

hover event with on() 方法自 jQuery 版本 1.8 起已弃用,并从 jQuery 版本 1.9 起完全删除。

所以现在您可以根据需要使用 hover() method to handle the event or separately use mouseenter or mouseleave event with on() 方法。

$('li.dropdown-toggle').hover(function () {
    $(this).find(".submenu").slideToggle(200);
});


// or with on 

$('li.dropdown-toggle').on('mouseenter mouseleave', function () {
    $(this).find(".submenu").slideToggle(200);
});