var viewing = 0;
var formSection = document.getElementById("myform").getElementsByTagName("div");
var submitbutton = document.getElementById("submitbutton");
document.getElementById("nextbutton").onclick = function() {viewFormSection(viewing + 1);}
function sectionValid(section)
{
var tempInputs = formSection[section].querySelectorAll("input, select, textarea");
for(var i = 0; i < tempInputs.length; i++)
{
if(!tempInputs[i].checkValidity())
{
return false;
}
}
return true;
}
function viewFormSection(section)
{
//Validate the current section before proceeding.
if(!sectionValid(viewing))
{
submitbutton.click();
return false;
}
//Code that hides the current form section and shows the desired one.
viewing == section;
}
HTML 将在您尚未到达的部分中的隐藏字段上生成错误,因为它不喜欢这些字段不能被聚焦。但是当你读到最后一部分的时候,它就不再是一个问题了。