
function CocosSelector(root, selector) {
    var selector;
    var root;
 
    var sOut = [];

    function loop(node) {
        if (CocosSelector.nodeMatch(node, selector)) {
            sOut.push(node);
        }
        var childs = node.getChildren();
        for (var i = 0; i < childs.length; i++) {
            
            loop(childs[i]);

        }
    }
    loop(root);

    return sOut;

}


/**
*Ծʽӹϵѯ
* $("#panel .112")  112 panelԪصԪصԪ.
*·һ node Ƿһ ʽѡַ.
*/
CocosSelector.nodeMatch = function (node, selector) {
    var result = false;
    var selectorArr = selector.split(' ');
    var currentSelector = selectorArr.pop();

    if (CocosSelector.singleNodeMatch(node, currentSelector)) {
        result = true;
        currentSelector = selectorArr.pop();
    } else {
        return false;
    }

    function loop(n) {
        if (!currentSelector) {
            return ;
        } 
        
        if (CocosSelector.singleNodeMatch(n, currentSelector)) {
            currentSelector = selectorArr.pop();
            result = true;

        }
        var parent = n.getParent();
        if (parent) {
            loop(parent);
        } else {
            if (currentSelector) {
                result = false;
                return;
            }
        }
    }
  
 
    var parent = node.getParent();
    if (parent) {
        loop(parent);
    }

    return result;
   


}




/**
* 򵥲ѯһnode Ƿһ ѡ
*  #id 鿴  node Ƿ name=id
*/
CocosSelector.singleNodeMatch = function(node, selector) {
    var f = selector[0];
    switch (f) {
        case "#":
            var s = selector.substr(1);
            var nodeName = node.getName();
            var reg = new RegExp('^'+s+'$', "ig");
            return reg.test(nodeName);
            ; break;
        case ".":
            var s = selector.substr(1);
            var nodeTag = node.getTag().toString();
            var reg = new RegExp('^' + s + '$', "ig");
            return reg.test(nodeTag);
            ; break;
        default :
            var className = node._className;
            var reg = new RegExp('^' + selector + '$', "ig");
            return reg.test(className);
            ; break;
    }
}
@@ -407,15 +407,22 @@
 **%0A*
-%D4%BE%CA%BD%D3%B9%CF%B5%D1%AF
+%E8%A7%A3%E5%86%B3%E8%B7%B3%E8%B7%83%E5%BC%8F%E7%88%B6%E5%AD%90%E5%85%B3%E7%B3%BB%E6%9F%A5%E8%AF%A2
 %0A*
+%E5%A6%82
  $(%22
@@ -443,36 +443,63 @@
  112
+%E5%8F%AF%E8%83%BD%E5%9C%A8
  panel
-%D4%AA%D8%B5%D4%AA%D8%B5%D4%AA.%0A*%C2%B7%D2%BB node %C7%B7%D2%BB %CA%BD%D1%A1%D6%B7
+%E7%9A%84%E5%AD%90%E5%85%83%E7%B4%A0%E7%9A%84%E5%AD%90%E5%85%83%E7%B4%A0%E7%9A%84%E5%AD%90%E5%85%83%E7%B4%A0%E9%87%8C.%0A*%E4%BB%A5%E4%B8%8B%E6%96%B9%E6%B3%95%E6%A3%80%E6%9F%A5%E4%B8%80%E4%B8%AA node %E6%98%AF%E5%90%A6%E6%BB%A1%E8%B6%B3%E4%B8%80%E4%B8%AA %E5%A4%8D%E5%90%88%E5%BC%8F%E9%80%89%E6%8B%A9%E5%99%A8%E5%AD%97%E7%AC%A6%E4%B8%B2
 .%0A*/
@@ -1438,37 +1438,53 @@
 *%0A* 
-%F2%B5%A5%B2%D1%AF%D2%BBnode %C7%B7%D2%BB %D1%A1
+%E7%AE%80%E5%8D%95%E6%9F%A5%E8%AF%A2%E4%B8%80%E4%B8%AAnode %E6%98%AF%E5%90%A6%E6%BB%A1%E4%B8%80%E4%B8%AA %E5%8D%95%E7%82%B9%E9%80%89%E6%8B%A9%E5%99%A8
 %0A* 
+%E5%A6%82
  #id 
-%E9%BF%B4 
+%E5%88%99%E4%BB%85%E6%9F%A5%E7%9C%8B %E8%AF%A5
  node 
-%C7%B7
+%E6%98%AF%E5%90%A6
  nam

修正一处 编码错误 统一改成utf8