使用标记/样式刷新UI按钮的"咏叹调"

Ali*_*tos 2 checkbox label jquery-ui uilabel checked

我正在使用带有样式UI按钮 - 像| B | 我| U | 在此示例页面中,生成的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>
Run Code Online (Sandbox Code Playgroud)

当我将"aria-pressed"属性更改为"true"时,按钮根本不会改变...我试过这种方式,但它不起作用:

var myhappyidtest = 2;

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

Run Code Online (Sandbox Code Playgroud)

我看到在按钮的情况下,它可以刷新.但是我不知道在这种情况下如何用label做这个.

有人有想法吗?

Ali*_*tos 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');
    }
});
Run Code Online (Sandbox Code Playgroud)

UPDATE

正如@Gnought和@Vladimir所建议的,并使用@Vladimir的方法,这里是这个问题的更新答案:

var myhappyidtest = 2;

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

由于该示例的原始链接已关闭,我在这里做了一个示例:http://jsfiddle.net/psycocandy/8SpGd/1/

感谢您的建议.