$('.pagination ul li').each({
if( $(this).index(this) > 2 )
{
$(this).hide();
}
});
SyntaxError: missing : after property id 有什么问题?
$('.pagination ul li').each({
if( $(this).index(this) > 2 )
{
$(this).hide();
}
});
SyntaxError: missing : after property id 有什么问题?
function使用前面的关键字{},否则它将被解释为对象文字。
$('.pagination ul li').each(function() {
if ($(this).index(this) > 2) {
$(this).hide();
}
});
此外,$(this).index(this)不符合您的预期。是否要检查元素所在的索引是否大于 2?请改用此修订版:
$('.pagination ul li').each(function(idx) {
if (idx > 2) {
$(this).hide();
}
});
你需要通过.each一个function. 如果没有function(),它将被读取为对象 ( {})。
$('.pagination ul li').each(function(){
if($(this).index(this) > 2){
$(this).hide();
}
});
PS$(this).index(this)不会像您认为的那样做。它会在里面搜索this,this因此它总是返回0。
如果您想要 中的索引li,请ul使用 中的索引参数.each。
$('.pagination ul li').each(function(index){
if(index > 2){
$(this).hide();
}
});
PPS 如果您只想隐藏具有 s 的lis index > 2,那么您可以更轻松地执行此操作:
$('.pagination ul li:gt(2)').hide();