我試圖在按下按鈕時更改按鈕的數據主題。按下時更改按鈕主題
我打電話按鈕的onClick處理這個JavaScript函數:
function changeNextButtonColor() {
var nextButton = document.getElementById('next');
nextButton.setAttribute('data-theme', 'a');
}
但主題沒有改變。有任何想法嗎?
我試圖在按下按鈕時更改按鈕的數據主題。按下時更改按鈕主題
我打電話按鈕的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>
這將工作正常 – ghostCoder
function changeNextButtonColor() {
$('#next').attr({'data-theme': 'a'});
}
如果您使用jQuery,這是您的代碼。
您的代碼有效;其他事情出錯了。 JavaScript控制檯(Web Inspector,Firebug,Dragonfly ...)說什麼?是否有任何錯誤報告? –
謝謝你們!也許不工作,因爲按鈕是輸入提交? –