示例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<style>
.border{
width: 100px;
height: 100px;
background-color: red;
}
.border:hover{
background-color: green !important;
}
</style>
<script>
function changeBackgroundColor(){
document.getElementById("border").style.backgroundColor="blue";
}
</script>
</head>
<body>
<div id="border" class="border" οnclick="changeBackgroundColor()"></div>
</body>
</html>
上面的代码去掉 !important 之后,.border:hover会失效。