单击jQuery Mobile时按钮更改颜色 [英] Button change color on click jQuery Mobile

查看:275
本文介绍了单击jQuery Mobile时按钮更改颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码可以更改点击按钮的颜色:

I've this code to change a color of a button on click:

$('.fav').live('click', function(e) { 

  $(this).buttonMarkup({ theme: "b" });

});

如何再次单击该按钮恢复为正常颜色(主题c)?

How can I return to normal color (theme c) by clicking the button again?

有什么办法可以查看按钮的状态吗?

Is there any way to see the state of a button?

推荐答案

由于必须实时运行,因此您可以进行自己的切换:

As it has to be live then you could just make your own toggle:

$('.fav').live('click', function() {
    var dotoggle = $(this).attr("dotoggle");
    if ( dotoggle == "1"  ) {
        $(this).buttonMarkup({ theme: "c" });
        $(this).attr("dotoggle","0");
     }
     else {
        $(this).buttonMarkup({ theme: "b" });
        $(this).attr("dotoggle","1");
    }
});

JSF定制切换示例的中间部分: http://jsfiddle.net/PLx8v/3/

JSFiddle of a custom toggle example: http://jsfiddle.net/PLx8v/3/

这篇关于单击jQuery Mobile时按钮更改颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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