jquery 소스 - jquery ()
                                            
 8379 단어  jqueryjavascriptjquery1.8.2
                    
원본 95~289 줄, jquery.fn 핵심 함수(utils)
jQuery.fn = jQuery.prototype = {
	constructor: jQuery,
	init: function( selector, context, rootjQuery ) {},//     
	// Start with an empty selector
	selector: "",
	// The current version of jQuery being used
	jquery: "1.8.2",//    
	// The default length of a jQuery object is 0
	length: 0,//  jquery        
	// The number of elements contained in the matched element set
	size: function() {},//       
	toArray: function() {},//    
	// Get the Nth element in the matched element set OR
	// Get the whole matched element set as a clean array
	get: function( num ) {},//  jquery     num+1   
	// Take an array of elements and push it onto the stack
	// (returning the new matched element set)
	pushStack: function( elems, name, selector ) {},// DOM    elems  jquery  
	// Execute a callback for every element in the matched set.
	// (You can seed the arguments with an array of args, but this is
	// only used internally.)
	each: function( callback, args ) {},// jQuery.each
	ready: function( fn ) {},// jQuery.ready.promise()
	eq: function( i ) {},//   i+1   
	first: function() {},//       
	last: function() {},//        
	slice: function() {},
	map: function( callback ) {},
	end: function() {},
	// For internal use only.
	// Behaves like an Array's method, not like a jQuery method.
	push: core_push,
	sort: [].sort,
	splice: [].splice
};
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
init 방법 init 방법은 실제적으로 juqery의 주 함수 $() 또는 jQuery() $() 인자:selector: 선택기(문자열,dom 요소,수 그룹,함수,jQuery 대상,null,undefined,false) content: 찾을 DOM 요소 집합, 문서 또는 jQuery 대상입니다.rootjQuery: 현재 문서 역할 영역의 루트 노드
init: function( selector, context, rootjQuery ) {
		var match, elem, ret, doc;
		// Handle $(""), $(null), $(undefined), $(false)
		if ( !selector ) {
			return this;
		}
		// Handle $(DOMElement)     ,  DOM   $(body)
		if ( selector.nodeType ) {
			this.context = this[0] = selector;
			this.length = 1;
			return this;
		}
		// Handle HTML strings //html   
		if ( typeof selector === "string" ) {//''        $('')
			if ( selector.charAt(0) === "" && selector.length >= 3 ) {
				// Assume that strings that start and end with <> are HTML and skip the regex check
				match = [ null, selector, null ];
			} else {// html      #id      
                                
				match = rquickExpr.exec( selector );
			}
			// Match html or make sure no context is specified for #id
			if ( match && (match[1] || !context) ) {
                                //  $("Hello
")
				// HANDLE: $(html) -> $(array)
				if ( match[1] ) {
					context = context instanceof jQuery ? context[0] : context;
					doc = ( context && context.nodeType ? context.ownerDocument || context : document );
					// scripts is true for back-compat
					selector = jQuery.parseHTML( match[1], doc, true );
					if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
						this.attr.call( selector, context, true );
					}
					return jQuery.merge( this, selector );
				// HANDLE: $(#id)
				} else {
					elem = document.getElementById( match[2] );
					// Check parentNode to catch when Blackberry 4.6 returns
					// nodes that are no longer in the document #6963
					if ( elem && elem.parentNode ) {
						// Handle the case where IE and Opera return items
						// by name instead of ID
						if ( elem.id !== match[2] ) {
							return rootjQuery.find( selector );
						}
						// Otherwise, we inject the element directly into the jQuery object
						this.length = 1;
						this[0] = elem;
					}
					this.context = document;
					this.selector = selector;
					return this;
				}
			// HANDLE: $(expr, $(...))
			} else if ( !context || context.jquery ) {
				return ( context || rootjQuery ).find( selector );
			// HANDLE: $(expr, context)
			// (which is just equivalent to: $(context).find(expr)
			} else {
				return this.constructor( context ).find( selector );
			}
		// HANDLE: $(function) 
                // $(function(){ 
                     //Document is ready
                //});
		// Shortcut for document ready
		} else if ( jQuery.isFunction( selector ) ) {
			return rootjQuery.ready( selector );
		}
		if ( selector.selector !== undefined ) {
			this.selector = selector.selector;
			this.context = selector.context;
		}
		return jQuery.makeArray( selector, this );
	}
 1.jQuery() 또는 $()
//Handle $(""), $(null), $(undefined), $(false), $()
if ( !selector ) {
	return this;//     
}
2. jQuery(element) 또는 $(element)
// Handle $(DOMElement)     ,  DOM   $(body)
if ( selector.nodeType ) {
	this.context = this[0] = selector;//      context    DOM  
	this.length = 1;
	return this;
}
3. jQuery(') 또는 $(')
// Handle $('',document.forms[0]) 
//     "ddd시나닷컴asd"   ,  match[1]   "시나닷컴"
if ( match[1] ) {
    context = context instanceof jQuery ? context[0] : context;//context    jQuery  
    //     ,     DOM   ,     ,   document  
    doc = ( context && context.nodeType ? context.ownerDocument || context : document );
    // scripts is true for back-compat
    selector = jQuery.parseHTML( match[1], doc, true );
    if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
        this.attr.call( selector, context, true );
    }
    return jQuery.merge( this, selector );
}else{
 //
}
4.jQuery(#id) 또는 $(#id)
{
    //match[2]   #id   ,  match[2]      id     , “#name” match[2]  “name”
    elem = document.getElementById( match[2] );
    // Check parentNode to catch when Blackberry 4.6 returns
    // nodes that are no longer in the document #6963
    if ( elem && elem.parentNode ) {
        // Handle the case where IE and Opera return items
        // by name instead of ID
        //  IE Opera      getElementById        name        ,           name      
        if ( elem.id !== match[2] ) {
            return rootjQuery.find( selector );
        }
        // Otherwise, we inject the element directly into the jQuery object
        this.length = 1;
        this[0] = elem;
    }
    this.context = document;
    this.selector = selector;
    return this;
}
5.jQuery(callback) 또는 $(callback)
   return rootjQuery.ready( selector );//      function 
6.jQuery(expr, $(...))또는 $(expr, $(...),예를 들어 $("div>p", $(...), $("input:radio",document.forms[0]),$("div.foo",document.forms[0])
if ( !context || context.jquery ) {
   return ( context || rootjQuery ).find( selector  );//
}
7. 상기 모든 상황 외의 기타 상황
    // HANDLE: $(expr, context)
    return this.constructor( context ).find( selector );
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
jQuery 전후 예이 기사에서는 jquery after() 및 before() 메소드의 예를 볼 것입니다. before() 메서드는 선택한 요소 앞에 지정된 콘텐츠를 삽입합니다. after() 메서드는 선택한 요소 뒤에 지정된 콘텐츠...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.