티스토리 뷰
/**
* jquery.simple.validator.js . 폼의 유효성 검사
* 예)
* 폼.vaildator().check();
*
*/
;(function($){
var Validator = (function(){
//의존 관계 정의
var he = Hello.world
// 비공개 프로퍼티
,form, opts, errors = [], elements = [], messages= [], checked_result = false, that;
// 비공개 메서드
// var 선언을 마침
//초기화 필요하면 초기화 진행
that = {
version : '1.0'
, setOption : function(name , option ) {
opts[name] = option;
}
, getOption : function( name ) {
return opts[name];
}
}
return $.extend( {}, that, {
init : function(element, options){
form = element;
opts = $.extend({}, $.fn.validator.defaults, options);
return this;
}
, check : function(){
console.log( opts );
return true;
}
});
}());
$.fn.validator = function( option ){
var $this = $(this)
, data = $this.data('validator')
, options = typeof option == 'object' && option;
if ( !data ) {
$this.data('validator', ( data = Validator.init(this, options) ) );
}
if ( typeof option == 'string' ) {
data[option]();
}
return data;
};
$.fn.validator.defaults = {
checkClass : 'valid'
};
})(jQuery);
var valid = $("#memberForm").validator({'checkClass' : 'vvvv' }).check();
console.log( valid );
var valid2 = $("#memberForm2").validator({'checkClass' : 'bbb' });
console.log( valid2.check() );
valid2.setOption( 'checkClass', 'ccc' );
'웹개발 > Jquery' 카테고리의 다른 글
| jquery.Callback 소개 (0) | 2012.05.09 |
|---|---|
| jquery xml 를 ie가 파싱 못할 경우 . (0) | 2012.03.15 |
| jQuery Custom Event Sample (0) | 2012.03.06 |
| animate 페이드 하면서 움직이는 이중 효과 (0) | 2012.02.02 |
| jQuery 모듈 패턴 (3) | 2011.08.12 |
댓글