更改按钮主题时pressed [英] Change button theme when pressed

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

问题描述

我试图改变时pressed按钮的数据主题。

I'm trying to change the data-theme of a button when pressed.

我在按钮的onClick处理程序调用此JavaScript函数:

I'm calling this JavaScript function in the button's onClick handler:

function changeNextButtonColor() {
    var nextButton = document.getElementById('next');
    nextButton.setAttribute('data-theme', 'a');
}

但主题是不会改变。任何想法?

but the theme is not changing. Any ideas?

推荐答案

一旦你设置主题设置上的按钮,你将需要调用刷新上像这样低于...

Once you've set set the theme on the button you'll need to call "refresh" on it like this below...

$("#next").attr("data-theme","a").button('refresh');

如果您想这种行为绑定到所有下一步按钮,在过程及其可能不止一个,那么你可能要考虑做一些更喜欢这一点。它会检查每个页面有一类colorChangeButton,然后,点击后,主题是按钮属性的数据主题 - pressed。

If you want to bind this kind of behavior to all "next" buttons in a process and their might be more than one then you might want to consider doing something more like this. It will checked every page for a button that has a class of colorChangeButton and then, when clicked, change the theme to the alternate theme specified on that buttons attribute of data-theme-pressed.

<a href="#" data-role="button" class="colorChangeButton" data-theme-pressed="a" data-theme="b">Next</a>

<script type='text/javascript'>
    $('div').live('pageinit', function(){
        $("a.colorChangeButton).click(function(){
           var $thisButton = $(this);
           $thisButton.attr("data-theme",$thisButton.attr("data-theme-pressed")).button('refresh');
        });
    });
</script>

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

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