문제

I have a group of radio inputs with associated labels. There is some CSS magic to pretty up the buttons, and this works fine. I need to be able to change the selected attribute of the label.

<input type='radio' id='radio1' name='resolution' value='0' selected />
<input type='radio' id='radio2' name='resolution' value='1' />
<label for='radio1' class='cb-enable selected' ><span>Open</span></label>
<label for='radio2' class='cb-disable ' ><span>Closed</span></label>

How would I go about setting the label selector with jQuery?

도움이 되었습니까?

해결책

$("input:radio[name='resolution']").change(function(){
    $("label").removeClass("selected");
    $("label[for='" + this.id + "']").toggleClass("selected", this.checked);
});

http://jsfiddle.net/QKL5t/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top