2

如何更改選定的單選按鈕背景顏色?jQuery Mobile:如何更改單選按鈕的活動狀態顏色

$("input[type='radio']").click(function(e) { 
    $("input[type='radio']").css('background-color', '#ff0000'); 
}); 

我試過這個..但它不起作用。


它不是working.I忘記分享我的代碼

<fieldset data-role="controlgroup" id="custom-fieldset"> <span>Were you able to complete your visit today?</span><br/><input type="radio" id="radio_1134198__4516395" name="sdid_1134198" value="radio_1134198__4516395" /><label for="radio_1134198__4516395">Yes</label>

我得到的結果是這樣http://i.stack.imgur.com/SDGeZ.png。單選按鈕的顏色必須改變。

回答

4

工作實施例:http://jsfiddle.net/Gajotres/qkCZY/

版本1

HTML:

<form> 
    <fieldset data-role="controlgroup" data-type="horizontal" id="custom-fieldset"> 
     <legend>Horizontal:</legend> 
     <input name="radio-choice-h-2" id="radio-choice-h-2a" value="on" checked="checked" type="radio"/> 
     <label for="radio-choice-h-2a">One</label> 
     <input name="radio-choice-h-2" id="radio-choice-h-2b" value="off" type="radio"/> 
     <label for="radio-choice-h-2b">Two</label> 
     <input name="radio-choice-h-2" id="radio-choice-h-2c" value="other" type="radio"/> 
     <label for="radio-choice-h-2c">Three</label> 
    </fieldset> 
</form> 

CSS:

#custom-fieldset div .ui-radio .ui-radio-on { 
    background: red !important; 
} 

2版

工作例如:http://jsfiddle.net/Gajotres/hTY6k/

HTML:

<fieldset data-role="controlgroup" id="custom-fieldset"> 
    <legend>Were you able to complete your visit today?</legend> 
    <label for="radio_1134198__4516395">Yes</label> 
    <input type="radio" id="radio_1134198__4516395" name="sdid_1134198" value="radio_1134198__4516395"/> 
</fieldset> 

CSS:

#custom-fieldset div .ui-radio label span .ui-icon-radio-on { 
    background-color: red !important; 
} 

最後說明

如果您想了解更多關於如何自定義jQuery Mobile頁面和小部件,然後看看這個article。它附帶了很多工作示例,其中包括爲什麼!對於jQuery Mobile來說非常重要。