本帖最后由 mengnanleo 于 2011-06-16 16:14:46 编辑

解决方案 »

  1.   

    原理就是a b 不管干了啥最终都是执行
    return this;
      

  2.   

    顶,这就相当于把$('#id')当做返回值返回了,如果修改了$('#id')的话end()就派上作用了
      

  3.   

    如果修改了$('#id')的话end()就派上作用了怎么说呀
      

  4.   

    返回值:jQuery
    end()
    概述
    回到最近的一个"破坏性"操作之前。即,将匹配的元素列表变为前一次的状态。如果之前没有破坏性操作,则返回一个空集。所谓的"破坏性"就是指任何改变所匹配的jQuery元素的操作。这包括在 Traversing 中任何返回一个jQuery对象的函数--'add', 'andSelf', 'children', 'filter', 'find', 'map', 'next', 'nextAll', 'not', 'parent', 'parents', 'prev', 'prevAll', 'siblings' and 'slice'--再加上 Manipulation 中的 'clone'。示例
    描述:
    选取所有的p元素,查找并选取span子元素,然后再回过来选取p元素HTML 代码:
    <p><span>Hello</span>,how are you?</p>jQuery 代码:
    $("p").find("span").end()结果:
    [ <p><span>Hello</span> how are you?</p> ]
    看看文档吧
    例子
    $("p").find("span").end().a().b().b()
    a()和b()还是对$("p")操作,而不是$("p span")
      

  5.   

    汗了,大哥,我是自己在写呀,没有用jquery
      

  6.   

    简单写法(function(){
    var MN=function(ele){
    if(!ele) return false;
    ele=ele.split(/\s/);
    var $=selector(ele);
    function selector(ele){
    return (ele.length==2)?document.getElementById(ele[0]).getElementsByTagName(ele[1]):document.getElementById(ele[0]);
    }
    return{
    getOffset:function(){
    var top=0,left=0;
    while($!= null){
    top+=$.offsetTop;
    left+=$.offsetLeft;
    $=$.offsetParent;
    }
    return {top:top,left:left};
    },
    opacity:function(v){
    if(typeof v!='number') v=100;
    if(!-[1,]) $.style.filter='alpha(opacity='+v+')';
    $.style.MozOpacity=v/100;
    $.style.opacity=v/100;
    return this
    },
    html:function(v){
    if(!v) return $.innerHTML;
    $.innerHTML=v;
    return this;
    },
    eq:function(v){
    if(typeof v=='number') $=$[v];
    return this;
    }
    }
    }
    window.$=MN;
    })()
    正常写法(function(){
    var MN=function(selector){
    return new MN.fn.init(selector);
    }
    MN.fn=MN.prototype={
    init:function(selector){
    if(selector){
    selector=selector.split(' ');
    this.$=(selector.length==2)?document.getElementById(selector[0]).getElementsByTagName(selector[1]):document.getElementById(selector[0]);
    }
    return this;
    },
    eq:function(v){
    if(typeof v=='number') this.$=this.$[v];
    return this;
    },
    getOffset:function(){
    var top=0,left=0;
    while(this.$!= null){
    top+=this.$.offsetTop;
    left+=this.$.offsetLeft;
    this.$=this.$.offsetParent;
    }
    return {top:top,left:left};
    },
    html:function(v){
    if(!v) return this.$.innerHTML;
    this.$.innerHTML=v;
    return this;
    },
    opacity:function(v){
    if(typeof v!='number') v=100;
    if(!-[1,]) this.$.style.filter='alpha(opacity='+v+')';
    this.$.style.MozOpacity=v/100;
    this.$.style.opacity=v/100;
    return this;
    },
    extend:function(obj){
    for(var i in obj){
    this[i]=obj[i];
    }
    }
    }
    MN.fn.init.prototype=MN.fn;
    window.$=MN;
    })()
    第一种是不是不能使用extend,想不到怎么满足而且貌似第一种不太灵活,函数不能相互调用