代码:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 200px;
height: 200px;
background-color: #d58512;
} .bgc-1{
background-color: hotpink;
}
</style>
</head>
<body>
<div class="bgc-1"></div>
<script>
let divEle = document.getElementsByTagName("div")[0]; setInterval(function () {
divEle.classList.remove("bgc-1");},2000); // 设置1秒后执行func函数(只调用一次)
setTimeout(func,1000); function func() {
setInterval(function () {
divEle.classList.add("bgc-1")},2000)
}
</script>
</body>
</html>
05-20 18:52