2011-04-12 26 views
2

我使用的UI buttons with style - Like | B | I | U | in this example page,和HTML結構生成這個樣子:刷新「詠歎調壓」與標記UI按鍵/類型

<div class="radiocheck ui-buttonset"> 
<input type="radio" name="radio1" value="1" id="radio0" class="ui-helper-hidden-accessible"> 
<label for="radio0" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false"> 
    <span class="ui-button-text">Sobre</span> 
</label> 
<input type="radio" name="radio1" value="2" id="radio1" class="ui-helper-hidden-accessible"> 
<label for="radio1" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false"> 
    <span class="ui-button-text">Politica</span> 
</label> 
<input type="radio" name="radio1" value="3" id="radio2" class="ui-helper-hidden-accessible"> 
<label for="radio2" aria-pressed="true" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false"> 
    <span class="ui-button-text">Outros</span> 
</label> 
<input type="radio" name="radio1" value="4" id="radio3" class="ui-helper-hidden-accessible"> 
<label for="radio3" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right" role="button" aria-disabled="false"> 
    <span class="ui-button-text">Promocoes</span> 
</label> 

當我改變「詠歎調-pressed」 propertie到‘真’,按鈕不會改變在所有...我tryed這種方式,但它沒有工作:

 
var myhappyidtest = 2;

$('.radiocheck input').each(function(i){ if(myhappyidtest == $(this).val()){ $(this).next('label').attr('aria-pressed', 'true'); } });

我看到ŧ帽子在按鈕的情況下,有可能刷新。 但我不知道如何在這種情況下使用標籤來做到這一點。

有人有想法嗎?

+0

我認爲詠歎調屬性是專門爲輔助技術來幫助傳達信息,以禁用的用戶。我不相信它對按鈕的外觀有任何影響。 – clamchoda 2011-04-12 20:58:05

+0

謝謝克里斯!我找到了解決方案......非常簡單! =)我只是將** ui-state-active **類添加到元素,然後將** aria-pressed **設置爲** true **並且它可以工作! – 2011-04-13 11:23:25

+0

不是問題,快樂編碼;) – clamchoda 2011-04-13 14:40:03

回答

5

我只是將「ui-state-active」類添加到元素,它的工作原理!

var myhappyidtest = 2; 

$('.radiocheck input').each(function(i){ 
    if(myhappyidtest == $(this).val()){ 
     $(this).next('label').attr('aria-pressed', 'true'); 
     $(this).next('label').addClass('ui-state-active'); 
    }else{ 
     $(this).next('label').attr('aria-pressed', 'false'); 
     $(this).next('label').removeClass('ui-state-active'); 
    } 
}); 

UPDATE

至於建議的@Gnought和@Vladimir,並使用@Vladimir的方法,這裏是一個更新的回答這個問題:

var myhappyidtest = 2; 

$('#format input[value="' + myhappyidtest + '"]').attr('checked', true).button('refresh'); 

由於原文鏈接的例子是關閉的,我在這裏做了一個例子:http://jsfiddle.net/psycocandy/8SpGd/1/

謝謝你的建議。

+1

詠歎調和UI狀態活動受JQuery內部變化。我認爲這種方法不被推薦。 – Gnought 2014-07-16 07:47:44

2

其實,你應該讓jQuery用戶界面做的造型:

$(this).attr('checked', false); 
$(this).button('refresh');