[英]html&js vadilation of radio button
大家好,我正在尝试验证单选按钮。 一旦提交而不单击按钮,它将是文本输入旁边的红色警告文本,如此图像
代码在下面,如果有人解决此问题,我将不胜感激。
<html>
<head>
<link rel ="stylesheet" type="text/css" href="456.css">
<meta charest ="utf-8">
<title>error-msg will not display correctly at the same time</title>
<script>
function validation(thisForm) {
// other
if(!thisForm.other.value.length)
{
document.getElementById('other-error').style.display= "inline-block";
}
else
{
document.getElementById('other-error').style.display= "none";
}
if (!thisForm.other.value.length) {
return false;
}
return true;
}
</script>
<style>
.error-msg {
display: none;
color:red;
border: 1px solid;
width: 120px;
margin-left: 10px;
}
</style>
</head>
<body>
<form action="#" onSubmit="return validation(this);">
<fieldset>
<div class="Other">
<label for="other">Other</label>
<input type="radio" id="other" name="other" />
<input type="text" id="o-text" name="o-text">
<span class="error-msg" id="other-error">other error</span>
</div>
</fieldset>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>```
您可以检查已检查的属性。
if(document.getElementById("yourRadiobuttonID").checked==false){
document.getElementById('other-error').style.display= "inline-block";
}
else{
document.getElementById('other-error').style.display= "none";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.