最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to change color on button when disabled then turn back when enabled - Stack Overflow

programmeradmin1浏览0评论

I have a button that is pre-styled so the disabled color doesn't look disabled when the button is disabled. I can't take off the prestyling so what I want to do is say something like:

if button is disabled, show this color, else return this color.

The code below shows a button that is disabled for 30 seconds on page load.

<script type="text/javascript" >
  window.onload = function()
      {
         var btn = document.getElementsByName('submit')[0];
         btn.disabled  = true;

         setTimeout(function(){btn.disabled  = false;}, 30000);

      };

I have a button that is pre-styled so the disabled color doesn't look disabled when the button is disabled. I can't take off the prestyling so what I want to do is say something like:

if button is disabled, show this color, else return this color.

The code below shows a button that is disabled for 30 seconds on page load.

<script type="text/javascript" >
  window.onload = function()
      {
         var btn = document.getElementsByName('submit')[0];
         btn.disabled  = true;

         setTimeout(function(){btn.disabled  = false;}, 30000);

      };

Share asked Feb 5, 2014 at 12:55 user3270936user3270936 111 gold badge2 silver badges3 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

You can simply do it using CSS3 :disabled Selector

input[type="submit"]:disabled
{
    background:#CCC;
}

You can use addClass :

<script type="text/javascript" >
  window.onload = function()
      {
         var btn = document.getElementsByName('submit')[0];
         btn.disabled  = true;
         btn.setAttribute("class", "your_class");
         setTimeout(function(){btn.disabled  = false;}, 30000);

      };

Have you tried this?

input[disabled='disabled']{
    //different style
}
发布评论

评论列表(0)

  1. 暂无评论