我试图逐步完成表格,在" tab"我只有收音机按钮,我想无法继续前进,直到他们中的一个人没有被选中这样的代码:
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the current tab
function showTab(n) {
// This function will display the specified tab of the form ...
var x = document.getElementsByClassName("tab");
x[n].style.display = "block";
// ... and fix the Previous/Next buttons:
if (n > 0) {
document.getElementById("prevBtn").style.display = "inline";
document.getElementById('submBtn').style.display = "none";
} else {
document.getElementById("prevBtn").style.display = "none";
document.getElementById('submBtn').style.display = "none";
document.getElementById("nextBtn").style.display = "inline";
}
if (n == (x.length - 1)) {
document.getElementById("nextBtn").style.display = "none";
document.getElementById('submBtn').style.display = "inline";
} else {
document.getElementById("nextBtn").InnerHTML = "Next";
}
// ... and run a function that displays the correct step indicator:
fixStepIndicator(n)
}
function validateForm() {
// This function deals with validation of the form fields
var x, y, i, valid = true;
x = document.getElementsByClassName("tab");
y = x[currentTab].getElementsByTagName("input");
// A loop that checks every input field in the current tab:
for (i = 0; i < y.length; i++) {
// If a field is empty...
if (y[i].value == "" || getElementsByTagName("selector").prop('checked', true)) {
// add an "invalid" class to the field:
y[i].className += " invalid";
// and set the current valid status to false:
valid = false;
}
}
// If the valid status is true, mark the step as finished and valid:
if (valid) {
document.getElementsByClassName("step")[currentTab].className += " finish";
}
return valid; // return the valid status
}
单选按钮的名称是&#34;选择器&#34;,我已尝试按标签名称,按类型,按类别,按ID调用它们,尝试检查是否已选中通过函数prop(),以及 name .checked == true
的ckeck状态,它不起作用; /任何sugestions? :)