在单击时更改单选按钮的背景颜色可以通过以下步骤实现:
<input type="radio" id="radioButton" name="color" value="red">
<label for="radioButton">Red</label>
function changeBackgroundColor() {
var radioButton = document.getElementById("radioButton");
if (radioButton.checked) {
radioButton.style.backgroundColor = "red";
} else {
radioButton.style.backgroundColor = "";
}
}
<input type="radio" id="radioButton" name="color" value="red" onclick="changeBackgroundColor()">
<label for="radioButton">Red</label>
现在,当单选按钮被单击时,它的背景颜色将变为红色。可以根据需要修改changeBackgroundColor函数中的代码来更改背景颜色的逻辑。
相关产品推荐:腾讯云无需提及。
领取专属 10元无门槛券
手把手带您无忧上云