DOM 요소를 검색 할 때 jQuery가 리턴 오브젝트를 작성하는 방법을 이해하려고합니다. 나는 근원을 살펴 봤지만, 이해할 수 있는지 완전히 확신 할 수 없으며, 여기 누군가가 나에게 약간의 통찰력을 줄 수 있기를 바랬다.jQuery 리턴 오브젝트 이해하기
jQuery DOM을 쿼리 할 때 jQuery는 일치하는 DOM 요소를 찾은 다음 요소의 인덱스를 새 객체의 키로 사용하여 일치하는 DOM 요소를 객체로 추가합니다. this
반환
if (rsingleTag.test(match[1]) && jQuery.isPlainObject(context)) {
for (match in context) {
// Properties of context are called as methods if possible
if (jQuery.isFunction(this[ match ])) {
this[ match ](context[ match ]);
// ...and otherwise set as attributes
} else {
this.attr(match, context[ match ]);
}
}
}
return this;
모든 방법을 포함하는 전체의 jQuery 오브젝트를 반환한다. 내가 지금이 시점까지 가지고 있니?
이제는 css, find, ajax, hide 등과 같은 모든 기능이 나타납니다. jQuery.fn 객체에 있습니다. 어떻게 든
(그리고 나는 이것이 내가 보이지 않아요 어디라고 생각합니다),이 기능은하지 DOM 요소 자체에 있지만, 같은 CSS를 사용하여 access.js https://github.com/jquery/jquery/blob/master/src/core/access.js
var access = jQuery.access = function(elems, fn, key, value, chainable, emptyGet, raw) {
을 통해,라고 예를 들어, 우리가
jQuery.extend({
css: function(elem, name, extra, styles) {...
jQuery.fn.extend({
css: function(name, value) {
return access(this, function(elem, name, value) {
var styles, len,
map = {},
i = 0;
if (jQuery.isArray(name)) {
styles = getStyles(elem);
len = name.length;
for (; i < len; i++) {
map[ name[ i ] ] = jQuery.css(elem, name[ i ], false, styles);
}
return map;
}
return value !== undefined ?
jQuery.style(elem, name, value) :
jQuery.css(elem, name);
}, name, value, arguments.length > 1);
내가 나는 우리가 그 호출 jQuery.fn.extend.css 방법에 $('div').css(...)
를 호출하는 거지, 거기에서, 액세스 메소드가 호출되는 방법입니다없는 것 같아 acc와는 다른 서명 핵심 jQuery에서 초기화 된 ess 메소드 우리는 지속적으로 jQuery[0],jQuery[1]
를 교체하는 경우
또한, 어떻게 내가 가질 수있다 : 그들은 모두 같은 jQuery를 개체를 반환하는 경우
var divs = $('div');
var spans = $('span');
문서 태그의 두 가지 설정을 유지? 나는 그 물체가 업데이트 될 것이라고 생각했다.
나는 이것이 어떻게 작동하는지 완전히 오해하고 있습니까? JQuery와 DOM 쿼리 할 때 원본을 판독 수집 할 수있는 것과
디버거에서 "단계별"접근은 어떻게됩니까?': /' – Stphane