Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.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
使用Javascript删除CSS悬停功能_Javascript_Css_Asp.net - Fatal编程技术网

使用Javascript删除CSS悬停功能

使用Javascript删除CSS悬停功能,javascript,css,asp.net,Javascript,Css,Asp.net,我需要使用JavaScript删除CSS悬停功能 我在表单上有一个按钮,用于将数据提交到我们的db服务器。使用ASP.NET按钮控件的OnClientClick,我想使用getElementById将元素的文本更改为“提交…”,将按钮的背景色更改为浅灰色,更重要的是禁用以下内容。按钮:CSS中的悬停效果 .button:hover, .content-form input.button:hover, #comment-form #submit:hover { backgroun

我需要使用JavaScript删除CSS悬停功能

我在表单上有一个按钮,用于将数据提交到我们的db服务器。使用ASP.NET按钮控件的OnClientClick,我想使用getElementById将元素的文本更改为“提交…”,将按钮的背景色更改为浅灰色,更重要的是禁用以下内容。按钮:CSS中的悬停效果

.button:hover, 
.content-form input.button:hover, 
#comment-form #submit:hover   
{
    background-color: #333;
}
我真正感兴趣的是删除/禁用上述CSS的Javascript

e.g. OnClientClick="getElementByID('ButtonName').blahblahblah;"

首先,你的css是错误的。应该是:

.button:hover, .content-form input.button:hover, #comment-form, #submit:hover    {
    background-color: #333;
}
您正在添加带有id和类的css。你不应该那样做。只需添加类并使用document.getElementById'submit'。删除属性'class'

工作小提琴:


编辑:很抱歉在我回答之前没有注意到问题的最后一部分:

在本例中,它删除了class属性,删除了所有已定义的类,但添加了不应删除的类

功能失效悬停元素{ 删除“类”属性的元素; 元素setAttribute'class','other'; } .按钮:悬停{ 背景色:333; } .另一个{ 背景颜色:浅灰色; }
悬停有很多解决问题的方法

例如:

1-使用HTML禁用属性

2-添加替代上一样式的类

.button:hover, 
.content-form input.button:hover, 
 #comment-form #submit:hover    
 {
    background-color: #333;
 }

 .button.submitted:hover
 {
    background-color: gray;
 }
Js:


等等

谢谢。使用我的CSS报价按钮:悬停等。。您能详细说明一下在上面的示例中应该用什么替换类吗?据我所知,您希望删除悬停样式,但不希望删除类本身。正当
OnClientClick="getElementByID('ButtonName').disabled=true;
.button:hover, 
.content-form input.button:hover, 
 #comment-form #submit:hover    
 {
    background-color: #333;
 }

 .button.submitted:hover
 {
    background-color: gray;
 }
OnClientClick="getElementByID('ButtonName').className = "submitted";