问题描述
我正在尝试在 Javascript 中运行一个条件,如果用户选择了 4 个单选按钮 ID 中的一个,它会将表单提交按钮从禁用更改为启用。 我有以下代码,但我不确定出了什么问题:
function validation(e) {
var bt = document.getElementById('btSubmit');
if (document.getElementById('1').checked && document.getElementById('1').checked && document.getElementById('2').checked && document.getElementById('4').checked && document.getElementById('5').checked) {
bt.disabled = false;
}
else if (document.getElementById('3').checked) {
document.getElementById("error").innerHTML = "Are you sure you do have not opinion?";
document.getElementById("error").style.color = "green";
document.getElementById("error").style.fontSize = "22px";
document.getElementById("error").style.borderStyle = "solid";
}
else {
e.preventDefault();
document.getElementById("error").innerHTML = "You should fill this question";
document.getElementById("error").style.color = "red";
document.getElementById("error").style.fontSize = "30px";
document.getElementById("error").style.borderStyle = "solid";
}
}
<form>
<fieldset>
<legend>Background Details</legend>
<label for="age">Age:</label>
<input type="text" id="age" name="age" placeholder="Enter your age"><br />
<label for="age">Occupation:</label>
<input type="text" id="occupation" name="occupation">
</fieldset><br /><br />
<h2>Select the best option:</h2>
<label for="bars">To what extent did you enjoy the project?</label><br />
<label for="bars">1 (Not at all)</label>
<input type="radio" value="1" id="1">
<input type="radio" value="2" id="2">
<input type="radio" value="3" id="3">
<input type="radio" value="4" id="4">
<input type="radio" value="5" id="5">
<label for="bars">5 (Very much)</label>
<br /><br />
<input type="button" value="Validate" onclick="validation()"><br />
<input type="submit" value="Submit" id="btSubmit" disabled>
</form>
<p id="error"></p>
非常感谢您的帮助。 您的帮助总是帮助我学习和改进。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)