Change color of button during keypress

后端 未结 3 770
终归单人心
终归单人心 2021-01-24 21:49

I want to change the color of a


when it is clicked by a mouse or while pressing the enter key.<

3条回答
  •  粉色の甜心
    2021-01-24 22:27

    Please try following code

               $('.button').keypress(function(e){
                  if(e.which == 13){
                      $(this).css('background-color','#FFF');
                  }
                });
    
                $('.button').keyup(function(e){
                  if(e.which == 13){
                      $(this).css('background-color','');
                  }
                });
    

提交回复
热议问题