Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何将单选按钮状态设置为使用css检查?_Html_Css_Radio Button - Fatal编程技术网

Html 如何将单选按钮状态设置为使用css检查?

Html 如何将单选按钮状态设置为使用css检查?,html,css,radio-button,Html,Css,Radio Button,我有一组默认选中的单选按钮。像这样: <input type="radio" name="radioButton" id="rd1" checked=""> <input type="radio" name="radioButton" id="rd2"> <input type="radio" name="radioButton" id="rd3"> <input type="radio" name="radioButto

我有一组默认选中的单选按钮。像这样:

    <input type="radio" name="radioButton" id="rd1" checked="">
    <input type="radio" name="radioButton" id="rd2">
    <input type="radio" name="radioButton" id="rd3">
    <input type="radio" name="radioButton" id="rd4">
    <input type="radio" name="radioButton" id="rd5">


我知道有很多方法可以用javascript添加checked属性。我的问题是如何使用css将选中的属性添加到选中的单选按钮?

如果要更改初始选中框,只需将“checked”属性移动到HTML中所需的元素即可,如果要设置当前选中框的样式,可以使用以下CSS选择器:
input[type=checkbox]:checked
,如果要通过单击复选框以外的任何其他操作更改选中状态,则必须使用JS


属性“checked”不同于JS中的实际
。checked
属性:而
elem.getAttribute('checked')
将只返回
null以外的值。如果属性已在HTML中设置(也可以通过JS更改),
elem.checked
将始终返回布尔值(真/假)指示当前是否选中此框。

CSS(顾名思义)用于设置样式。DOM操作应该使用Javascript完成。