刷新“aria-pressed”带有标记/样式的 UI 按钮

发布于 2024-11-01 09:19:28 字数 1971 浏览 2 评论 0原文

我正在使用 UI 按钮,样式如下|乙|我|你|在这个示例页面中,生成的 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 输入').each(function(i){ if(myhappyidtest == $(this).val()){ $(this).next('label').attr('aria-pressed', 'true'); } });

我发现在按钮情况下,可以刷新。 但我不知道如何在这种带有标签的情况下做到这一点。

有人有主意吗?

I'm using the UI buttons with style - Like | B | I | U | in this example page, and the html structure generated look like this:

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

When I change the "aria-pressed" propertie to "true", the button doesn't change at all... I tryed this way, but it didn't work:

var myhappyidtest = 2;

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

I saw that in button cases, it's possible to refresh.
But I don't have idea on how to do this in this case with label.

Someone have an idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫瑟鸿黎 2024-11-08 09:19:28

我只需将“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/

感谢您的建议。

I just add the "ui-state-active" class to the element and it works!

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

As suggested by @Gnought and @Vladimir, and using the approach of @Vladimir, here's an updated answer to this question:

var myhappyidtest = 2;

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

As the original link of the example is off, I've made an example here: http://jsfiddle.net/psycocandy/8SpGd/1/

Thank you for the suggestions.

若无相欠,怎会相见 2024-11-08 09:19:28

实际上,你应该让 jquery ui 来做样式:

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

Actually, you should let jquery ui do the styling:

$(this).attr('checked', false);
$(this).button('refresh');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文