Javascript Jquery";事件对象";“试图改变”;CSS";属于<;部门>;标签不工作

Javascript Jquery";事件对象";“试图改变”;CSS";属于<;部门>;标签不工作,javascript,jquery,html,css,Javascript,Jquery,Html,Css,index.html: <html> <head> <title>chapter 5</title> <script src="jquery.js"></script> <script src="app.js"></script> </head> <body> <div > <p>this is a pa

index.html:

<html>
<head>
    <title>chapter 5</title>
    <script src="jquery.js"></script>
    <script src="app.js"></script>

</head>
<body>
    <div >
        <p>this is a paragraph</p>
    </div>
</body>
</html>
所以,根据我的Jquery:当我将鼠标移到标签上时,它应该将其颜色更改为红色,而当任何其他标记(除了鼠标)进入时,它应该更改为蓝色。但什么都没有发生

我用event尝试过其他功能,但效果相当不错。我不明白为什么这个功能不起作用。我可能需要用“css”做点什么吗?

来自jQuery的方法文档:

在jQuery 1.8中不推荐使用,在1.9中删除:名称
“hover”
用作字符串
“mouseenter mouseleave”
的缩写。它为这两个事件附加一个事件处理程序,处理程序必须检查
event。键入
以确定事件是
mouseenter
还是
mouseleave
。不要将
“hover”
伪事件名称与接受一个或两个函数的
.hover()
方法混淆

收听
mouseenter
mouseleave
事件,而不是
悬停

$("div").on("mouseenter mouseleave", function(event) {
   $(this).css("background", event.type === "mouseenter" ? "blue" : "red");
});
或者,您可以将对象传递给
.on()
方法:

$("div").on({
   mouseenter: function() {
      $(this).css("background", "blue");
   },
   mouseleave: function() {
      $(this).css("background", "red");
   }
});

我想知道为什么您从一开始就没有使用
mouseenter
。请记住,不要像在代码中那样增加开销。我实际上是在尝试一本书中的一些示例来学习jQuery。有趣的是,这本书是在2013年出版的,并且仍然使用“hover”(已删除)。
$("div").on({
   mouseenter: function() {
      $(this).css("background", "blue");
   },
   mouseleave: function() {
      $(this).css("background", "red");
   }
});