我覺得這個解決方案很簡單,但我無法在互聯網上找到它。如果選擇單選按鈕,我需要在單選按鈕及其標籤上顯示邊框。單選按鈕代碼爲例如:讓一個單選按鈕及其標籤在選中時自動更改
<input type="radio" name="sex" class="sex" value="0">Male</input>
<input type="radio" name="sex" class="sex" value="1">Female</input>
如果選擇了男性選項,則整個單選按鈕和男性標籤將被矩形包圍。如果選擇了女性單選按鈕,則男性單選按鈕上的矩形將消失並更改爲女性單選按鈕。但是這隻需要在CSS中完成。根本沒有JavaScript。這可能嗎?我認爲答案可能與假選擇器有關,如:
.sex {border: 0}
.sex:checked {border: 1 solid red;}
但是這不起作用。有什麼我做錯了嗎?謝謝。
檢查這個http://code.stephenmorley.org/html-and-css/styling-checkboxes-and-radio-按鈕/#下載 – user00000341 2015-04-04 07:01:18
chech這一個幫助http://www.tutorialrepublic.com/faq/how-to-create-custom-radio-buttons-using-css-and-jquery.php – 2015-04-04 07:02:13