好奇,為什么eq不支持index為負(fù)數(shù)?
j = +i + ( i < 0 ? len : 0 );單看哪里,這句代碼根本沒有必要
return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );這句完全可用用i直接判斷
好奇,為什么eq不支持index為負(fù)數(shù)?
j = +i + ( i < 0 ? len : 0 );單看哪里,這句代碼根本沒有必要
return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );這句完全可用用i直接判斷
2014-11-06
舉報
2015-08-03
eq支持負(fù)數(shù)——從后向前取元素
j = +i + ( i < 0 ? len : 0 ); 將值為負(fù)的索引轉(zhuǎn)換成對應(yīng)正數(shù)所對應(yīng)的索引
比如:$('li').eq(-1) ? ?假如有10個li元素: $('li').length = 10. ? ?j = +i + ( i < 0 ? len : 0 ); 則 j = 9. 也就是取 this.pushStack(this[9]) == $('li').eq(9)的jQuery對象。 ?可以自己驗(yàn)證一下。
2015-05-24
好像支持負(fù)數(shù)的吧,j = +i + ( i < 0 ? len : 0 );這句話就是讓他支持負(fù)數(shù),即將負(fù)數(shù)的下標(biāo)轉(zhuǎn)換成真正的第幾個索引,this數(shù)組里可是索引從0開始的
2015-01-23
哪里說了 eq 不支持負(fù)數(shù)
2014-12-24
好像是如此