CSS切换按钮?

C_M*_*jor 4 javascript css jquery cordova

是否可以在PhoneGAP中使用CSS切换按钮?我想要一个按钮,如果点击它会改变颜色,再次点击它必须回到默认颜色.知道怎么做吗?

我已经编辑了我的帖子,我们很容易帮助我,因为现在我真的很困惑如何做到这一点,简单的东西,但技巧.

  `This the function 

  function toggle(ths) {

   //CSS color
   $(ths).toggleClass("btnColor");
   $("#tb").toggleClass("btnColorR")

   //Get value clicked
   var clicked = $(ths).val();

   //diplay on web-page
   $("#lblType").html(clicked);
   $("#setCount").html(" minutes : " + minutes + " seconds : " + seconds);

   //duration time count
   seconds = seconds + 1;
   if (seconds % 60 == 0) {
      minutes += 1;
   seconds = 0;
 }
        timer = setTimeout("toggle()", 1000);   
  }


 The CSS

.btnColor
 {
 background-color:blue;  
 color:white;  
 }
.btnColorR {
 background-color:green;
}


  This is how my buttons are created.

 function createButtons(tbID, tbClass, tbType, tbValue, onClick) {
     return '\n<input '
        + (tbID ? ' id=\'' + tbID + '\'' : '')
        + (tbClass ? ' class=\'' + tbClass + '\'' : '')
        + (tbType ? ' type=\'' + tbType + '\'' : '')
        + (tbValue ? ' value=\'' + tbValue + '\'' : '')
        + (onClick ? ' onclick=\'toggle(this);' + onClick + '\'' : '')
        + '>';
 }

 function DisplayButtons(cableData) {
  var newContent = '';
   $.each(cableData,

    function (i, item) {
       newContent += createButtons("tb" + item.CommonCable, null, "submit",       item.CommonCable, toggle);
   });
   $("#planned").html(newContent);
 }`
Run Code Online (Sandbox Code Playgroud)

Mos*_*rdy 5

考虑你的按钮是#butt:

$("#butt").click(function(){
     $(this).toggle('red');
})
Run Code Online (Sandbox Code Playgroud)

和CSS:

.red{
 color:red;
}
Run Code Online (Sandbox Code Playgroud)