[英]jQuery .Last Function Return Boolean
Ok so heres whats going on: 好的,这是怎么回事:
Whenever I click on an image nested in an unordered list, it moves to a different part on the page. 每当我单击嵌套在无序列表中的图像时,它就会移动到页面的其他部分。 But when it reaches the last li, I want it not to move. 但是,当它到达最后一个li时,我希望它不动。 I am trying to find it out if there is anyway that the .last() function can return a boolean back? 我试图找出它是否存在.last()函数是否可以返回布尔值吗?
Thanks, Rohan 谢谢,罗汉
Instead of .last()
which returns the last element in the set, for a given set if you have an element you can use .is()
with :last-child
, like this: 对于给定的集合,如果您有一个元素,则可以将.is()
与:last-child
一起使用,而不是.last()
返回集合中的最后一个元素,如下所示:
//abort out at top of the function
if($(this).closest('li').is(':last-child')) return;
If the <li>
is the last in the list, it'll return true
for is(':last-child')
. 如果<li>
是列表中的最后一个,它将为is(':last-child')
返回true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.