jQuery Validate는 동일한 이름의 여러 인스턴스 공유를 확인합니다.

小云云
풀어 주다: 2018-01-12 09:07:58
원래의
1805명이 탐색했습니다.

이 글에서는 다수의 동일한 이름을 확인하는 jQuery Validate 방법을 주로 소개합니다. 필요한 친구들이 참고하면 도움이 될 것입니다.

소개:

양식 페이지에 다음 코드가 있습니다.

 <form>
  <input name="zhai"/><!-- 三个相同name的input -->
  <input name="zhai"/>
  <input name="zhai"/>
 </form>
로그인 후 복사

jquery 유효성 검사는 여러 개의 동일한 이름을 확인할 때 첫 번째 입력 상자만 확인합니다.

해결 방법 1:

양식 페이지에 해당하는 js에 다음 코드를 추가하세요. 현재 페이지에서만 다중 이름 확인을 해결할 수 있습니다.

 if ($.validator) {
   $.validator.prototype.elements = function () {
    var validator = this,
     rulesCache = {};
    return $(this.currentForm)
    .find("input, select, textarea")
    .not(":submit, :reset, :image, [disabled]")
    .not(this.settings.ignore)
    .filter(function () {
     if (!this.name && validator.settings.debug && window.console) {
      console.error("%o has no name assigned", this);
     }
     rulesCache[this.name] = true;
     return true;
    });
   }
  }
로그인 후 복사

해결 방법 2:

소스 파일 수정 모든 페이지에서 다중 이름 확인 가능

방법 1: jquery.validate.js 파일 수정

ctrl+F를 사용하여 ruleCache에서 this.name을 찾고 다음 코드를 주석 처리합니다.

elements: function() {
   var validator = this,
    rulesCache = {};
   // select all valid inputs inside the form (no submit or reset buttons)
   return $(this.currentForm)
   .find("input, select, textarea")
   .not(":submit, :reset, :image, [disabled]")
   .not( this.settings.ignore )
   .filter(function() {
    if ( !this.name && validator.settings.debug && window.console ) {
     console.error( "%o has no name assigned", this);
    }
    // 注释掉这里
    // select only the first element for each name, and only those with rules specified
    //if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
    // return false;
    //} 
    rulesCache[this.name] = true;
    return true;
   });
  },
로그인 후 복사

방법 2: jquery.validate.min.js 파일 수정

ctrl+F를 사용하여 검색하세요 (c[this.name]=!0,!0)})

 return !this.name && b.settings.debug && window.console && console.error("%o has no name assigned", this),
//this.name in c || !b.objectLength(a(this).rules()) ? !1 : (c[this.name] = !0, !0)//注释这行
c[this.name] = !0, !0 //添加这行
로그인 후 복사

관련 권장 사항:

Spring shiro bootstrap jquery.validate 로그인 및 등록 기능 구현 방법

jQuery Validate 양식 확인 플러그인 자세한 설명

jquery.validate.js 여러 개의 동일한 이름을 처리하는 방법에 대한 자세한 설명

위 내용은 jQuery Validate는 동일한 이름의 여러 인스턴스 공유를 확인합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!