如何解决用标记/样式刷新UI按钮的“按下aria”
|| 我正在使用具有样式的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>
当我将按“ aria-pressed”属性更改为“ true”时,该按钮完全没有改变……我尝试过这种方法,但是它不起作用:
var myhappyidtest = 2;
$(\'.radiocheck input\').each(function(i){
if(myhappyidtest == $(this).val()){
$(this).next(\'label\').attr(\'aria-pressed\',\'true\');
}
});
我看到在按钮情况下,可以刷新。
但是我不知道如何在这种情况下使用标签。
有人有主意吗?
解决方法
我只要将\“ 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/
感谢您的建议。
,实际上,您应该让jquery ui进行样式设置:
$(this).attr(\'checked\',false);
$(this).button(\'refresh\');
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。