JQuery 获取Dom元素的实例讲解
程序员文章站
2023-02-25 14:30:09
废话不多说,直接上代码
(function (window) {
var arr = [];
var vp = function (selector, con...
废话不多说,直接上代码
(function (window) { var arr = []; var vp = function (selector, context) { return new vp.fn.init(selector, context); } vp.fn = vp.prototype = { constructor: vp, init: function (selector, context) { var _document = window.document, elem, mark = selector.charat(0); if (mark == '#') { elem = _document.getelementbyid(selector.substring(1)); if (elem) { this[0] = elem; this.length = 1; } } return this; }, splice: arr.splice, }; vp.extend = vp.fn.extend = function () { var options, name, src, copy, copyisarray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = false; if (typeof target === "boolean") { deep = target; target = arguments[i] || {}; i++; } if (typeof target !== "object" && !vp.isfunction(target)) { target = {}; } if (i === length) { target = this; i--; } for (; i < length; i++) { if ((options = arguments[i]) != null) { for (name in options) { src = target[name]; copy = options[name]; if (target === copy) { continue; } if (deep && copy && (vp.isplainobject(copy) || (copyisarray = vp.isarray(copy)))) { if (copyisarray) { copyisarray = false; clone = src && vp.isarray(src) ? src : []; } else { clone = src && vp.isplainobject(src) ? src : {}; } target[name] = vp.extend(deep, clone, copy); } else if (copy !== undefined) { target[name] = copy; } } } } return target; }; vp.fn.extend({ get: function () { return this[0]; }, }); vp.fn.init.prototype = vp.fn; window.vp = vp; })(window);
以上这篇jquery 获取dom元素的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。