Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何避免悬停和活动css规则被javascript中以编程方式进行的css更改重写?_Javascript_Html_Css - Fatal编程技术网

如何避免悬停和活动css规则被javascript中以编程方式进行的css更改重写?

如何避免悬停和活动css规则被javascript中以编程方式进行的css更改重写?,javascript,html,css,Javascript,Html,Css,我有这个代码,改变按钮的颜色,在不到一秒钟的时间内将其恢复正常 document.getElementById("someid").style.color="#000000"; var clickAnimationIntervalId = setInterval(function({ document.getElementById("someid").style.color="#000000"; clearInterval(clickAnimationIntervalId); }

我有这个代码,改变按钮的颜色,在不到一秒钟的时间内将其恢复正常

document.getElementById("someid").style.color="#000000";
var clickAnimationIntervalId = setInterval(function({
    document.getElementById("someid").style.color="#000000";
    clearInterval(clickAnimationIntervalId);
}, 400);

工作正常,但执行此代码后,“someid”在悬停和活动状态下不再更改颜色,就像此代码在任何情况下更改了css颜色一样。如何避免这种行为?

这种行为是正确的

为了避免这种情况,创建一个类来设置someid的css,并将其添加到css中的:hover和.active状态

例如:

#someid.animationInterval {color:black}
#someid.animationInterval:hover,
#someid.animationInterval.active {*the same like your normal hover and active*}

现在通过Javascript设置animationInterval类。

此行为是正确的

为了避免这种情况,创建一个类来设置someid的css,并将其添加到css中的:hover和.active状态

例如:

#someid.animationInterval {color:black}
#someid.animationInterval:hover,
#someid.animationInterval.active {*the same like your normal hover and active*}

现在,您可以通过Javascript设置animationInterval类。

您可以将css类设置为悬停并使用激活颜色属性!重要的。例如:

a:hover, a:active{
  color: #5fba7d!important;
}

你可以把你的css类的悬停和积极的颜色属性!重要的。例如:

a:hover, a:active{
  color: #5fba7d!important;
}

这是因为
JS
您的风格
作为内联放置在按钮上。因此,它超越了您的默认样式。如果你想让它工作,你必须使用
!重要信息
与您的风格相关

button:hover{
 background-color:green !important;
}

这将完成您的工作。

这是因为
JS
您的风格作为内联放置在按钮上。因此,它超越了您的默认样式。如果你想让它工作,你必须使用
!重要信息
与您的风格相关

button:hover{
 background-color:green !important;
}

这将完成您的工作。

添加和删除一个类您对JavaScript代码有问题。document.getElementById(characterPressed)缺少引号。是,抱歉,已更正。询问时出错。这不是问题所在problem@SashaGrievus这是因为JS将您的样式作为内联样式放在按钮上。检查我的答案。添加和删除类您对JavaScript代码有问题。document.getElementById(characterPressed)缺少引号。是,抱歉,已更正。询问时出错。这不是问题所在problem@SashaGrievus这是因为JS将您的样式作为内联样式放在按钮上。检查我的答案。