$("li:gt(2)") can be used, but a long time ago I saw a jquery variable converted to XX and then used:gt(2), such as var $li=$(" li"), I need to use: gt(2) based on the $li variable. I don’t know if you understand what I mean. I am looking for an answer. I saw it on a blog a long time ago, but I can’t remember it.
伊谢尔伦2017-05-16 13:37:42
jquery itself does not have this method, only this selector, but you can extend it
$.fn.gt = function(num){
var after = [];
this.each(function(i){
if(i>=num){
after.push(this);
}
});
return after;
}
$.fn.lt = function(num){
var before = [];
this.each(function(i){
if(i<num){
before.push(this);
}
});
return before;
}