首页 > 解决方案 > 验证动态添加的必填字段时出现问题

问题描述

我有一个检查必填字段的通用脚本。应始终填写具有“必填”属性的字段。问题是现在我有一个强制输入,这取决于从其他输入中选择的选项,所以我动态添加/删除属性,但脚本没有检测到它。

有任何想法吗?我把功能代码留在这里

希望你理解 :D

function checkMandatory(id){
  var valid = true;
  var selector = "input[mandatory='']";
  if(id){
      selector = "#"+id+" :input[mandatory='']";
  }
  $(selector).each(function(){
      if($(this).val().trim()=="") {
          invalidarInput($(this), "The field is mandatory.");
          valid = false; 
      }
      else {
          $(this).val($(this).val().trim());
          $(this).removeClass("invalido");
          $(this).removeClass("tooltip");
          $(this).removeAttr("ttip");
          $(this).removeAttr("title");
          $(this).unbind("mouseover");
          $(this).unbind("mouseout");   
      }     
  });
return valid;

}

标签: javascriptjqueryhtml

解决方案


推荐阅读