2011-04-12 6 views
2

と私はUI buttons with style - Like | B | I | U | in this example pageを使用していて、HTMLの構造は次のようになり、生成:私は「アリアを変更すると更新 "ARIA-押された" 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> 

『「から propertie』真-pressed、ボタンは全く変化していない...私はこのようにしようと試みたが、それはうまくいきませんでした:

 
var myhappyidtest = 2;

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

私はトンを見ましたボタンケースの帽子は、をリフレッシュすることができます。 しかし、私はラベルでこの場合にこれを行う方法について考えていません。

誰かがアイデアを持っていますか?

+0

私はARIAの属性が無効なユーザーに情報を伝えるのに役立つ支援技術のために特別にと思っていました。私はそれがボタンの外観に何らかの影響を与えるとは思わない。 – clamchoda

+0

クリスおかげさま!私は解決策を見つけた...とても簡単! =)** ai-pressed **を** true **に設定する前に、** ui-state-active **クラスを要素に追加するだけです。 –

+0

問題ありません、ハッピーコーディング;) – clamchoda

答えて

5

"ui-state-active"クラスを要素に追加するだけで動作します。元のリンクとして

var myhappyidtest = 2; 

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

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のアプローチを使用したよう

、ここで更新この質問への答えですここでは例を挙げました:http://jsfiddle.net/psycocandy/8SpGd/1/

ありがとうございます。

+1

aria-pressedとui-state-activeはJQueryの内部変更の影響を受けます。私はこのアプローチが推奨されていないと思う。 – Gnought

2

実は、あなたはjQueryのスタイリングを行うUI聞かせください。

$(this).attr('checked', false); 
$(this).button('refresh'); 
関連する問題