鼠标悬停在jquery中不起作用

时间:2018-05-25 21:58:00

标签: jquery colors highlight

当光标越过它时,我试图使按钮高亮显示 html是:

<head>
<script src="jquery.js></script>
<scrips src="index.html"></script>
</head>

和index.js中的js

$(".button").mouseenter(function(){
 $(".button).css("background-color", "cyan");
 $(".button).css("color", "white");
});

3 个答案:

答案 0 :(得分:1)

$(".button").mouseenter(function(){
$(".button").css("background-color", "cyan");
$(".button").css("color", "white");
});

https://jsfiddle.net/nroqjuhn/

答案 1 :(得分:0)

jQuery和html中缺少引号

HTML

<html>
<head>
   <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
   <button class="button" type="button">Change my color</button>
   <script src="custom.js" type="text/javascript"></script>
</body>
</html>

custom.js

$(".button").mouseenter(function(){
 $(".button").css("background-color", "cyan");
 $(".button").css("color", "white");
});

答案 2 :(得分:0)

$(".button").mouseenter(()=>{$(".button")
   .css({"background-color":"cyan","color":"black"});
});

$(".button").mouseleave(()=>{$(".button")
   .css({"background-color":"#0084ff","color":"white"});
});