我希望我的div元素的顏色在用戶點擊後可以修復。但現在,即使用戶點擊它,它仍然會改變顏色。無法修復jQuery中div元素的背景顏色
這是我試過的代碼片段。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div").on({
mouseenter: function(){
$(this).css("background-color", "lightgray");
},
mouseleave: function(){
$(this).css("background-color", "lightblue");
},
click: function(){
$(this).css("background-color", "Red");
}
});
});
</script>
</head>
<body>
<div>Some Comment Text</div>
</body>
</html>
發生了什麼解釋更多! –
當我點擊div元素背景顏色是紅色但後來的顏色會改變。 你也可以運行代碼片段。 –