zoukankan      html  css  js  c++  java
  • jQuery的getText()方法源码

    /**
    * Utility function for retrieving the text value of an array of DOM nodes
    * @param {Array|Element} elem
    */
    getText = Sizzle.getText = function( elem ) {
    var node,
    ret = "",
    i = 0,
    nodeType = elem.nodeType;

    	if ( !nodeType ) {
    		// If no nodeType, this is expected to be an array
    		for ( ; (node = elem[i]); i++ ) {
    			// Do not traverse comment nodes
    			ret += getText( node );
    		}
    	} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
    		// Use textContent for elements
    		// innerText usage removed for consistency of new lines (see #11153)
    		if ( typeof elem.textContent === "string" ) {
    			return elem.textContent;
    		} else {
    			// Traverse its children
    			for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
    				ret += getText( elem );
    			}
    		}
    	} else if ( nodeType === 3 || nodeType === 4 ) {
    		return elem.nodeValue;
    	}
    	// Do not include comment or processing instruction nodes
    
    	return ret;
    };
  • 相关阅读:
    Linux文本检索命令grep笔记
    Python中字典的相关操作
    Go 语言函数闭包
    Go 语言多维数组
    Go 错误处理
    Go 语言接口
    Go 语言类型转换
    Go 语言递归函数
    Go 语言Map(集合)
    Go 语言范围(Range)
  • 原文地址:https://www.cnblogs.com/mackxu/p/gettext.html
Copyright © 2011-2022 走看看