读书人

jqeury和DOM的this指针有关问题

发布时间: 2012-04-03 12:38:19 作者: rapoo

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


[解决办法]
each里的this,不是代表each,而是被循环的对象

each=for的循环

例如
$(json).each(function(){
...this
})
这里的this代表 的就是json

读书人网 >JavaScript

热点推荐