写一个单选框用onchange判断
时间: 2024-05-22 11:15:26 浏览: 51
javascript checkbox/radio onchange不能兼容ie8处理办法
<html>
<body>
<form>
<input type="radio" name="gender" value="male" onchange="checkGender()"> Male<br>
<input type="radio" name="gender" value="female" onchange="checkGender()"> Female<br>
<input type="radio" name="gender" value="other" onchange="checkGender()"> Other<br>
</form>
<script>
function checkGender() {
var gender = document.querySelector('input[name="gender"]:checked').value;
alert("You selected " + gender);
}
</script>
</body>
</html>
阅读全文