求高手解惑 本帖最后由 mengnanleo 于 2011-06-16 16:14:46 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 原理就是a b 不管干了啥最终都是执行return this; 顶,这就相当于把$('#id')当做返回值返回了,如果修改了$('#id')的话end()就派上作用了 如果修改了$('#id')的话end()就派上作用了怎么说呀 返回值:jQueryend()概述回到最近的一个"破坏性"操作之前。即,将匹配的元素列表变为前一次的状态。如果之前没有破坏性操作,则返回一个空集。所谓的"破坏性"就是指任何改变所匹配的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") 汗了,大哥,我是自己在写呀,没有用jquery 简单写法(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,想不到怎么满足而且貌似第一种不太灵活,函数不能相互调用 两张图片,点击图片1获取焦点,图片2失去焦点。onFocus (JS)点击图标后把内容写入文本框的问题 这个问题该怎么解决 如何借用这个动画? 有这样的一个JS的问题,请教一下? 怎么样在父页面打开另一个页面? 新手请教! 为什么这样动态改变style不起作用呢? 如何用javascript写出通过onclick事件改变iframe的src? WSC居然不支持中文!!!有解决办法吗? firefox浏览器下,如何做到自动点击链接 HTML ocx遮住DIV
return this;
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")
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,想不到怎么满足而且貌似第一种不太灵活,函数不能相互调用