【问题标题】:Mouse over not working in jquery鼠标悬停在jquery中不起作用
【发布时间】:2018-11-05 08:00:27
【问题描述】:

我正在尝试在光标移过按钮时突出显示它
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");
});

【问题讨论】:

  • 您在 Javascript 中缺少引用。是在真实代码中还是复制错误?

标签: jquery colors highlight


【解决方案1】:
$(".button").mouseenter(function(){
$(".button").css("background-color", "cyan");
$(".button").css("color", "white");
});

https://jsfiddle.net/nroqjuhn/

【讨论】:

  • 除了修正报价错误之外,您还做了什么?
【解决方案2】:

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");
});

【讨论】:

  • 错别字应该用评论处理,不值得全面回答。
【解决方案3】:
$(".button").mouseenter(()=>{$(".button")
   .css({"background-color":"cyan","color":"black"});
});

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

【讨论】:

    猜你喜欢
    • 2013-05-11
    • 2015-08-08
    • 2011-04-06
    • 1970-01-01
    • 2015-04-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多