如何检查所有行上的字段是否为空?

时间:2018-10-08 12:51:27

标签: javascript jquery

我的jquery对话框该怎么办?弹出通知,字段为空,仅显示在第一行的空字段中。但是,在随后的行中,尽管字段为空,但这仍然无法正常工作。

function Save() {

      var par = $(this).parent().parent(); 
      var tdFirstName = par.children("td:nth-child(2)");
      var tdLastName = par.children("td:nth-child(3)");
      var tdAge = par.children("td:nth-child(4)");
      var tdButtons = par.children("td:nth-child(5)");

      tdFirstName.html(tdFirstName.children("input[type=text]").val());
      tdLastName.html(tdLastName.children("input[type=text]").val());
      tdAge.html(tdAge.children("input[type=text]").val());

      tdFirstName.html("<input type='text' id='txtName' value='" + tdFirstName.html() + "'/>");
      tdLastName.html("<input type='text' id='txtPhone' value='" + tdLastName.html() + "'/>");
      tdAge.html("<input type='text' id='txtEmail' value='" + tdAge.html() + "'/>");

      if ($('#txtName').val() == "" || $('#txtPhone').val() == "" || $('#txtEmail').val() == "") {

            alert('Please complete the field');

      } else {

          $('#btnAdd').removeAttr('disabled');
          $('.btnSave').attr('disabled','disabled');
          $('.btnEdit').removeAttr('disabled');
          $('.btnDelete').removeAttr('disabled');

          tdFirstName.find('input').attr('disabled', 'true');
          tdLastName.find('input').attr('disabled', 'true');
          tdAge.find('input').attr('disabled', 'true');

      }

      $(".btnSave").bind("click", Save);
      $(".btnEdit").bind("click", Edit);
      $(".btnDelete").bind("click", Delete);

    };

0 个答案:

没有答案