1 回答
TA贡献1825条经验 获得超4个赞
您应该附加一个onclick事件。当事件发生时,检查所有情况。正如我在下面描述的那样。
function radioClicked(){
let shapeChoice = document.querySelector('input[name="shape"]:checked').value;
switch (shapeChoice) {
case 'circV':
document.getElementById("debug1").innerHTML = "Circle Area"
break;
case 'rectV':
document.getElementById("debug1").innerHTML = "Rectangle Area"
break;
case 'triV':
document.getElementById("debug1").innerHTML = "Triangle Area"
break;
case 'paraV':
document.getElementById("debug1").innerHTML = "Parallelogram Area"
break;
default:
doucment.getElementById("debug1").innerHTML = "Default"
}
};
radioClicked();
<div id="radioHeader" onload="radioClicked()" onclick="radioClicked()" >
<input type="radio" name="shape" value="circV" onclick="" checked>
<label for="circleID">Circle</label>
<input type="radio" name="shape" value="rectV">
<label for="rectangleID">Rectangle</label>
<input type="radio" name="shape" value="triV">
<label for="triangleID">Triangle</label>
<input type="radio" name="shape" value="paraV">
<label for="parallelogramID">Parallelogram</label> <br>
<p id="debug1"></p>
</div>
添加回答
举报