简体   繁体   English

按下时更改按钮主题

[英]Change button theme when pressed

I'm trying to change the data-theme of a button when pressed. 我正在尝试在按下时更改按钮的数据主题。

I'm calling this JavaScript function in the button's onClick handler: 我在按钮的onClick处理程序中调用此JavaScript函数:

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');

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. 它将检查每个页面上是否有一个具有colorChangeButton类的按钮,然后在单击时将主题更改为在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>
function changeNextButtonColor() {
    $('#next').attr({'data-theme': 'a'});
}

If you're using jQuery, this is your code. 如果您使用的是jQuery,那么这就是您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM