Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多步骤表单Javascript_Javascript - Fatal编程技术网

多步骤表单Javascript

多步骤表单Javascript,javascript,Javascript,我正在尝试创建一个网站,我正在做一个多步骤的形式。该网站是一个汽车网站,所以有一个复选框的服务,汽车将需要。如换油、轮胎旋转、echeck等。在other下,我有一个文本输入框,但我不希望它处于活动状态,除非选中other。在我当前的JS中,我有它,因此用户在填写所有字段之前不能继续执行表单的下一步。但是代码检测到另一个文本框时,它没有被选中,不允许我进入下一步。如果有人能看看我的代码,看看我做错了什么,那就太好了 function validateForm() { // This func

我正在尝试创建一个网站,我正在做一个多步骤的形式。该网站是一个汽车网站,所以有一个复选框的服务,汽车将需要。如换油、轮胎旋转、echeck等。在other下,我有一个文本输入框,但我不希望它处于活动状态,除非选中other。在我当前的JS中,我有它,因此用户在填写所有字段之前不能继续执行表单的下一步。但是代码检测到另一个文本框时,它没有被选中,不允许我进入下一步。如果有人能看看我的代码,看看我做错了什么,那就太好了

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 == "") {
      // 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
}

function fixStepIndicator(n) {
  // This function removes the "active" class of all steps...
  var i, x = document.getElementsByClassName("step");
  for (i = 0; i < x.length; i++) {
    x[i].className = x[i].className.replace(" active", "");
  }
  //... and adds the "active" class to the current step:
  x[n].className += " active";
}

//check box other
document.getElementById('other').onchange = function() {
 if(this.checked==true){
  document.getElementById("othertext").disabled=false;
  document.getElementById("othertext").focus();
 }
 else{
  document.getElementById("othertext").disabled=true;
 }
};

在我看来,问题在于你得到的是所有的输入,不管它们是否被禁用,所以你需要考虑到这一点。由于您使用的是vanilla JS,因此可以使用validateForm函数中的IF条件执行以下操作:

if (y[i].value == "" && y[i].disabled === false) {
这样,它只会拾取未禁用的输入字段。

但代码会在未选中其他文本框时检测到另一个文本框,并且不会让我继续下一步。这是什么意思?