我遇到了一個選中的單選按鈕的樣式,我的代碼一般工作,除了有一個DEFAULT選中單選按鈕時,一些麻煩,然後造型不再工作,直到我檢查一個不同的單選按鈕。我的問題是,如何在缺省情況下選中應用於單選按鈕的同樣樣式,並且可以僅使用CSS來完成此操作?選中單選按鈕樣式
這裏是我的代碼:
HTML
<div class="accessOptions">
<div class="option">
<input type='radio' id="1" name='11' checked='checked' class="highlight"/>
<label for 1>Open to Anyone</label>
</div>
<div class="option">
<input type="radio" id="2" name="11" />
<label for 2>Only to Allowed Senders</label>
</div>
</div>
CSS:
.highlight {
background: #5479ab;
}
的jQuery:
$(document).ready(function(){
$('input:radio').change(function(){
var $this = $(this);
$this.closest('.accessOptions').find('div.highlight').removeClass('highlight');
$this.closest('.option').addClass('highlight');
});
});
鏈接的jsfiddle: http://jsfiddle.net/priswiz/BMB9R/
邊注:應該是'<標籤= 「1」>'和'不'