为什么我把jq的部分源码拿过来.却用不了呢?

时间:2021-09-13 14:43:03
(function(window, undefined ) {

var _$ = window.$,

rootjQuery,

// Support: IE<9
// For `typeof node.method` instead of `node.method !== undefined`
core_strundefined = typeof undefined,

_jQuery = window.jQuery,

core_version = "1.9.1",

// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
// Strict HTML recognition (#11290: must start with <)
rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,

// Match a standalone tag
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,

jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
};

jQuery.fn = jQuery.prototype = {
// The current version of jQuery being used
jquery: core_version,

constructor: jQuery,

init: function( selector, context, rootjQuery ) {
var match, elem;

// HANDLE: $(""), $(null), $(undefined), $(false)
if ( !selector ) {
return this;
}

// Handle HTML strings
if ( typeof selector === "string" ) {
if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
// Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ];

} else {
match = rquickExpr.exec( selector );
}

// Match html or make sure no context is specified for #id
if ( match && (match[1] || !context) ) {

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;


}
}
}

// All jQuery objects should point back to these
rootjQuery = jQuery(document);

// Limit scope pollution from any deprecated API
// (function() {

// })();
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
return jQuery;

})(window);


我是把jq的获取对象的入口代码拿下来...
<div class="" id="demo"></div>
console.log($("#demo"))  //这里根本获取不到jq对象

7 个解决方案

#1


有人吗。z。。。

#2


该回复于2013-07-05 08:25:24被管理员删除

#3


真是个才子啊

#4


这样可行吗,没有上下文的关联,独立拉出一份 为什么我把jq的部分源码拿过来.却用不了呢?

#5


引用 4 楼 splendid_java 的回复:
这样可行吗,没有上下文的关联,独立拉出一份 为什么我把jq的部分源码拿过来.却用不了呢?

還缺少哪段代碼啊?

#6


呵呵,这都什么问题。。

#7


该回复于2013-07-07 11:41:13被管理员删除

#1


有人吗。z。。。

#2


该回复于2013-07-05 08:25:24被管理员删除

#3


真是个才子啊

#4


这样可行吗,没有上下文的关联,独立拉出一份 为什么我把jq的部分源码拿过来.却用不了呢?

#5


引用 4 楼 splendid_java 的回复:
这样可行吗,没有上下文的关联,独立拉出一份 为什么我把jq的部分源码拿过来.却用不了呢?

還缺少哪段代碼啊?

#6


呵呵,这都什么问题。。

#7


该回复于2013-07-07 11:41:13被管理员删除