国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery對象初始化的傳參方式

2019-11-20 13:06:14
字體:
供稿:網(wǎng)友

jQuery對象初始化的傳參方式包括:

1.$(DOMElement)
2.$('<h1>...</h1>'), $('#id'), $('.class') 傳入字符串, 這是最常見的形式, 這種傳參數(shù)經(jīng)常也傳入第二個參數(shù)context指定上下文,其中context參數(shù)可以為$(...), DOMElement
3.$(function() {}); <===> $(document).ready(function() { });
4.$({selector : '.class', context : context}) <===> $('.class', context)

jQuery.fn = jQuery.prototype = {  constructor: jQuery,  init: function( selector, context, rootjQuery ) {    var match, elem, ret, doc;    // 處理$(""), $(null), $(undefined), $(false)這幾種參數(shù),直接返回this    if ( !selector ) {      return this;    }    // 當傳參selector為DOM結(jié)點時,將context置為selector    if ( selector.nodeType ) {      this.context = this[0] = selector;      this.length = 1;      return this;    }    // Handle HTML strings    // 當傳入的selector參數(shù)為字符串時,    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) ) {        // 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)    // Shortcut for document ready    // 當selector為function時相當于$(document).ready(selector);    } else if ( jQuery.isFunction( selector ) ) {      return rootjQuery.ready( selector );    }    // 當selector參數(shù)為{selector:'#id', context:document}之類時,重置屬性selector和context    if ( selector.selector !== undefined ) {      this.selector = selector.selector;      this.context = selector.context;    }    return jQuery.makeArray( selector, this );  }}; 

以上就是本文的全部內(nèi)容了,希望大家能夠喜歡。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 建瓯市| 平谷区| 志丹县| 周宁县| 武隆县| 枣强县| 沛县| 长宁县| 三河市| 乌鲁木齐县| 石景山区| 桃园市| 永清县| 宕昌县| 九江市| 长治县| 金昌市| 襄樊市| 东兴市| 盘锦市| 望谟县| 左贡县| 庆阳市| 阜阳市| 巴南区| 陆丰市| 永福县| 奉化市| 哈巴河县| 工布江达县| 永修县| 密云县| 瑞金市| 万山特区| 信宜市| 河北省| 固原市| 平乡县| 宽城| 东兰县| 海林市|