Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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
如何在单击时使用jQuery更改按钮颜色_Jquery_Html - Fatal编程技术网

如何在单击时使用jQuery更改按钮颜色

如何在单击时使用jQuery更改按钮颜色,jquery,html,Jquery,Html,我试图在使用jQuery单击时更改按钮的颜色 我希望按钮在单击时从蓝色变为灰色 到目前为止,我有这个代码 看 您只需更改单击按钮的背景色,如下所示 $(".vote-btn").click(function(){ $(this).css({"background-color":"grey"}); }); 看这把小提琴: 上述小提琴的更新版本,淡出后恢复蓝色: 转换单击的按钮 我建议使用jQuery添加一个CSS类,它将样式方面保留在CSS中,而不是将其直接放在逻辑中 J

我试图在使用jQuery单击时更改按钮的颜色

我希望按钮在单击时从蓝色变为灰色

到目前为止,我有这个代码


您只需更改单击按钮的背景色,如下所示

 $(".vote-btn").click(function(){
          $(this).css({"background-color":"grey"});
 });
看这把小提琴:

上述小提琴的更新版本,淡出后恢复蓝色:

转换单击的按钮


我建议使用jQuery添加一个CSS类,它将样式方面保留在CSS中,而不是将其直接放在逻辑中

JS

CSS


看起来你根本没有尝试过改变颜色。谷歌搜索中的“如何使用jquery改变背景颜色”会给出结果
 $(".vote-btn").click(function(){
          $(this).css({"background-color":"grey"});
 });
$(".vote-number").hide();

  $(".vote-btn").click(function(){
      $(this).css({'background':'grey'}).next('.vote-number').finish().show().fadeOut(5000);
  });
 $(".vote-btn").click(function(){
          $(this).next('.vote-number').finish().show().fadeOut(5000);
          $(this).css('background','grey');
      });
$(".vote-btn").click(function() {
    $(this)
        .addClass('clicked')
        .next('.vote-number')
        .finish()
        .show()
        .fadeOut(5000);
});
.vote-btn {
    background: blue;
    color: white;
    padding: 30px;
    margin-bottom: 30px;
}

.vote-btn.clicked {
    background: grey;
}