jQuery mouseenter事件未执行

时间:2016-08-06 13:04:32

标签: javascript jquery html css html5

我在页面中的div区域应用了 mouseenter事件时遇到了一些麻烦。我试图在鼠标输入时更改此div的背景颜色,但它只是被忽略了。

我有一个简单的HTML代码:

$(document).ready(function() {
  $("services-content-left").mouseenter(function() {
    console.log("enter");
    $(this).css("background-color", "yellow");
  });
});

JS和这个事件有关:

em1.style.background - color = "yellow";

正如我之前所说,当我进入这个div区域时,背景保持不变,没有任何变化。 HERE就是一个例子 你不知道如何解决它吗?

3 个答案:

答案 0 :(得分:2)

错误的选择器:)

$(document).ready(function() {
  $("#services-content-left").mouseenter(function() {
    console.log("enter");
    $(this).css("background-color", "yellow");
  });
});

答案 1 :(得分:1)

您的服务内容左侧之前错过了#

请将其更改为,

$("#services-content-left").mouseenter(function() {

工作小提琴: - https://jsfiddle.net/m2wpetp4/4/

希望这有帮助!

答案 2 :(得分:1)

你错过了

在你的代码中,应该是$("#services-content-left")而不是

$(document).ready(function() {
    $("#services-content-left").mouseenter(function() {
        console.log("enter");
        $(this).css("background-color", "yellow");
    });
});

表示ID选择器。

相关问题