簡體   English   中英

按下時更改按鈕主題

[英]Change button theme when pressed

我正在嘗試在按下時更改按鈕的數據主題。

我在按鈕的onClick處理程序中調用此JavaScript函數:

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

但主題並沒有改變。 有任何想法嗎?

一旦你設置了按鈕上的主題,你需要在其上調用“刷新”,如下所示...

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

如果你想將這種行為綁定到進程中的所有“下一步”按鈕並且它們可能不止一個,那么你可能想要考慮做更像這樣的事情。 它將檢查每個頁面上是否有一個具有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'});
}

如果您使用的是jQuery,那么這就是您的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM