鍍金池/ 問答/HTML/ css的設置沒有起作用?

css的設置沒有起作用?

hobby:<input id="x1" type="radio" name="sports" />x1
<input id="x2" type="radio" name="sports" />x2
<input id="x3" type="radio" name="sports" />x3
<input type="button" value="顯示" onclick="ShowChecked()">
<br>
<script> 
function ShowChecked(){
    $("input").css("backgroundColor","");
    $("input:checked").css("backgroundColor","red");
}    
</script>

選擇某個radio后,點擊 顯示 ,背景顏色沒有變紅哈?

回答
編輯回答
青檸

你的代碼是沒有問題的,你可以F12看一下,加的css屬性已經(jīng)加上去了,之所以沒有出現(xiàn)效果(bakground變紅)是因為,input radio設置background沒有效果。如果你要設置單選框的效果,你應該用input和label標簽結合起來,才能設置更好看的單選或者多選按鈕。

2017年2月8日 21:25
編輯回答
卟乖

選擇器沒問題,問題出現(xiàn)在input[type=radio]的背景顯示不了,或者說設置不了背景

你可以設置一下margin試試

function ShowChecked(){
    $("input").css("backgroundColor","");
    $("input:checked").css("margin","100px");
}    
2018年3月16日 16:23
編輯回答
大濕胸
<input type="button" value="顯示" onclick="ShowChecked">
2018年5月30日 23:55