2011-04-12 6 views
2
나는 UI buttons with style - Like | B | I | U | in this example page을 사용하고

및 HTML 구조는 다음과 같이 생성 : 나는 "아리아를 변경새로 고침 마크 업 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> 

-pressed " propertie 에"true "로, 버튼 내가이 방법을 tryed ... 전혀 변경되지 않습니다,하지만 작동하지 않았다 :

 
var myhappyidtest = 2;

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

나는 t을 보았다 단추 케이스의 모자는 으로 새로 고침이 가능합니다. 그러나이 경우 레이블을 사용하여이를 수행하는 방법에 대해서는 알지 못합니다.

누군가가 아이디어를 가지고 있습니까?

+0

내가 지원 전환 기술을 사용하지 않는 사용자에게 정보를 전달하기 위해의 아리아 속성이 특별히 있다고 생각했다. 단추의 모양에 영향을 미치지 않는다고 생각합니다. – clamchoda

+0

크리스! 나는 해결책을 찾았다. .. 매우 단순한! =) ** ai-pressed **를 ** true **로 설정하기 전에 요소에 ** UI 상태 ** 클래스를 추가하기 만하면됩니다! –

+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');