jquery怎么修改hover事件

2025年02月18日 建站教程

jquery怎么修改hover事件,下面web建站小编给大家详细介绍一下!

代码如下:

$(document).ready(function() {
  $("p").hover(function() {
    $("p").css("background-color", "red");
  }, function() {
    $("p").css("background-color", "blue");
  });
  
  $("button").click(function() {
    $("p").unbind("mouseenter").unbind("mouseleave");
  });
});

拓展介绍

/* 这种方法是错误的 */
$("id").unbind("hover");

/* 这种方法也是错误的 */
$("id").unbind("mouseover").unbind("mouseout");

/* 这种方法是新增的,在老的版本里是无法使用的 */
$("id").unbind("mouseenter mouseleave");

/* 这种方法正确的,新老版本皆可用 */
$("id").unbind("mouseenter").unbind("mouseleave");

本文链接:http://so.lmcjl.com/news/23412/

展开阅读全文
相关内容