Javascript IF输入声明

时间:2018-05-03 21:07:57

标签: javascript if-statement

我有以下条件来检查我的表中是否有空条目但是发生了一些非常奇怪的事情,每次代码检查第一个输入时它将其更改为TRUE或FALSE。即:

代码:空(空) 星期一:45.6
它应该只是向我显示警告而不是将代码更改为" TRUE"

 function Revisar_Espacios_Vacios(){

Rev_Tabla = document.getElementById("Registros");
Rev_len = document.getElementById("Registros").rows.length;

 for (y = 1; y < (Rev_len); y++) {

    for (x = 0; x <= 1; x++) {
        //Extraccion de la primera letra del codigo.

        if (x == 0) {

            Rev_Codigo = Rev_Tabla.rows[y].cells[0].getElementsByClassName('CLPMRY')[0]; //Code
            Rev_ck1 = Rev_Tabla.rows[y].cells[2].getElementsByClassName('NewR')[0]; //Amount

            alert(Rev_Codigo.value);    
            /*Check No°1 When there's no Code but Amount */
            if( Rev_Codigo.value == "" && Rev_ck1.value != ""){

                    alert('Codigo Faltante en la fila #' + y + " asignado el codigo: "  );
                    //Somehow this validation changes my Input InnerHtml to True or False
            }
            else
            {
            /*Check No°2 When there's No Amount but Code*/
            if( Rev_Codigo.value =! "" && Rev_ck1.value == "" ){    
                    alert('Letra mensual Faltante en la fila #' + y + " asignado el codigo: "  );

         //Somehow this validation changes my Input InnerHtml to True or False
            }

            else
            {

            }

        }
        }
        }
       }
  }

解决了

            Rev_Codigo = Rev_Tabla.rows[y].cells[0].getElementsByClassName('CLPMRY')[0]; //Code
            var Check_Code = Rev_Codigo.value;
            Rev_ck1 = Rev_Tabla.rows[y].cells[2].getElementsByClassName('NewR')[0]; //Amount
            var Check_ck1 = Rev_ck1.value;

     if( Check_Code == "" && Check_ck1 != ""){  
     alert('Codigo Faltante en la fila #' + y + " asignado el codigo: "  ); 
                }
                else
                {

    if( Check_Code != "" && Check_ck1 == "" ){  
    alert('Letra mensual Faltante en la fila #' + y + " asignado el codigo: "  );
                }

1 个答案:

答案 0 :(得分:2)

这是因为你的条件语法混淆了。

Rev_Codigo.value =!

应该是 Rev_Codigo.value != ""

在您的代码中,您正在做的是将Rev_Codigo.value分配给!"" true,因为""是假的。