改变按钮颜色点击并在其余时间保持不变? [英] change button color on-click and remains same for rest of the time?

查看:387
本文介绍了改变按钮颜色点击并在其余时间保持不变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我试图让我的按钮更改颜色的事情,以便用户可以看到他已经点击了按钮。即使他刷新页面,该按钮也会保持与先点击后的颜色相同。原因是im在一个页面上显示了很多按钮。这里是我的按钮代码。



< button id =ikkclass =btn btn-default btn-lg myBtnstyle =background:#ef332d; color:#fff; type =buttondata-uid =UZqTjJnRVdGQjQ> Procced< / button>

解决方案

这适用于我 http:// jsfiddle.net/wmy8vucb/6/

$(}> #myBtn).click(function(){$(this).addClass('myclass'); localStorage.setItem('clicked','1');}); if(localStorage.getItem(clicked)! = null){$(#myBtn).addClass('myclass');}

  .myclass {background-color:green!important;}  

 < button id =myBtnclass =btn btn-default btn-lg myBtnstyle =background:#ef332d; color:#fff; type =buttondata-uid =IeUtIMnV0V1JpQlU> Procced< / button>  

here is the thing I'm trying to make my button change colour so that user can see that he already clicked on the button. and even if he refreshes the page, the button will remain in the same colour as it was after he clicks first. the reason is that im showing a lot of buttons on one page. here is my button code.

<button id="ikk" class="btn btn-default btn-lg myBtn" style="background: #ef332d; color: #fff;" type="button" data-uid="UZqTjJnRVdGQjQ">Procced </button>

解决方案

this works for me http://jsfiddle.net/wmy8vucb/6/

$( "#myBtn" ).click(function() {

$(this).addClass('myclass');

localStorage.setItem('clicked', '1');

});



if(localStorage.getItem("clicked") != null){

$("#myBtn").addClass('myclass');


}

.myclass{
  background-color:green !important;
}

<button id="myBtn" class="btn btn-default btn-lg myBtn" style="background: #ef332d; color: #fff;" type="button" data-uid="IeUtIMnV0V1JpQlU">Procced</button>

这篇关于改变按钮颜色点击并在其余时间保持不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆