gpt4 book ai didi

JavaScript 代码无法检查单选按钮

转载 作者:行者123 更新时间:2023-12-02 16:42:44 24 4
gpt4 key购买 nike

我正在尝试进行验证以检查何时未选择单选按钮,如果未选择则应显示警报,但下面的代码不起作用。当按下按钮时,就应该进行验证

<html>
<head>
</head>

<body>
<form >
<input type="radio" id="b">
<input type="radio">

<button onClick="checkValidation()" type="button">Click Me!</button>
</form>
</body>


<script type="text/javascript">
function checkValidation(){
if (document.getElementById('b').checked == false) {
window.alert("sometext");
}
</script>
</html>

最佳答案

您的代码包含错误,缺少结束分号,},它应该是:

function checkValidation(){
if (document.getElementById('b').checked == false) {
window.alert("sometext");
}
} //This one is missing

关于JavaScript 代码无法检查单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27376345/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com