<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,ul,li{
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
ul{
width: 50px;
height: 80px;
}
li{
line-height: 20px;
width: 50px;
height: 20px;
border: 1px solid gray;
}
</style>
</head>
<body>
<ul>
<li>aaa</li>
<li>aaa</li>
<li>aaa</li>
<li>aaa</li>
</ul>
</body>
<script src="js/jquery.js"></script>
<script>
$("ul li").mouseover(function(){
$(this).css({backgroundColor:"red"})
})
$("ul li").mouseout(function(){
$(this).css({backgr
oundColor:""})
})
</script>
</html>
$("ul li").mouseout(function(){
$(this).css({backgr
oundColor:""})
})
===>换行语法出错了,改成下面的就可以了
$("ul li").mouseout(function () {
$(this).css({ backgroundColor: "" })
});
帮助到你可以点击右上角的采纳吗,谢谢~~
$(this).css({backgroundColor:"red"})
改为
$(this).css("backgroundColor","red");
试试。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body,ul,li{
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
}
ul{
width: 50px;
height: 80px;
}
li{
line-height: 20px;
width: 50px;
height: 20px;
border: 1px solid gray;
}
</style>
</head>
<body>
<ul>
<li>aaa</li>
<li>aaa</li>
<li>aaa</li>
<li>aaa</li>
</ul>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
$("ul li").mouseover(function(){
$(this).css({backgroundColor:"red"})
})
$("ul li").mouseout(function(){
$(this).css({backgroundColor:""})
})
</script>
</html>
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632