jQuery.fn.newTarget = function() {  
return this.each(function() {
if (this.host != window.location.host) { $(this).attr('target', '_new'); } });};
请问各位大侠 为什么each前面用this而不用$(this) each不是jquery函数吗 按说应该用jqeury对象调用才对呀

解决方案 »

  1.   

    each里的this,不是代表each,而是被循环的对象each=for的循环例如
    $(json).each(function(){
        ...this
    })
    这里的this代表 的就是json
      

  2.   

    函数中的this是可以指定的function a() {
        alert(this);
    }a(); // object Windowa.call(1); // 1jquery中将this指向两元素本身
      

  3.   

    因为这里面的this本身就已经是一个jquery对象了啊, 所以不用$号, $号是将其他[玩意儿]转换成jquery对象
      

  4.   

    我也不明白 为什么上面if分支里要用$(this) 我理解this用于DOM对象或属性(如:this.host)而$(this)用于jquery对像相应操作 这样的话each前面的this就很纠结了