3

スタイルのある UI ボタン​​を使用しています - Like | ビ | 私 | 私 | う | この例のページでは、生成された html 構造は次のようになります。

<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>

「aria-pressed」プロパティを「true」に変更すると、ボタンはまったく変更されません...この方法を試しましたが、機能しませんでした:

var myhappyidtest = 2;

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

ボタンの場合、リフレッシュできることがわかりました。しかし、この場合、ラベルを使用してこれを行う方法についてはわかりません。

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

4

2 に答える 2

7

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

アップデート

@Gnought と @Vladimir によって提案され、@Vladimir のアプローチを使用して、この質問に対する最新の回答を次に示します。

var myhappyidtest = 2;

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

例の元のリンクがオフになっているため、ここに例を作成しました: http://jsfiddle.net/psycocandy/8SpGd/1/

提案していただきありがとうございます。

于 2011-04-14T13:29:12.233 に答える
2

実際には、jquery ui にスタイリングを行わせる必要があります。

$(this).attr('checked', false);
$(this).button('refresh');
于 2013-03-25T10:28:53.573 に答える