怎么文本下拉和收起的功能HTML,jquery实现全部,收起,展开,显示,隐藏的类似下拉样式切换小例子,.parent()和.parents()的区别...

方法1:

下拉全部收起例子

.test {

padding: 10px;

color: #999999;

line-height: 150%;

padding-bottom: 15px;

border-bottom: 1px dotted #CCCCCC;

}

ul {

list-style-type: none;

}

  • a
  • b
  • c
  • d
  • d
  • d
  • d
  • d
  • g
  • h
  • j
  • k
  • k
  • k
  • k
  • k
  • k
  • 1
  • 2
  • 3
  • 4
  • 4
  • 4
  • 4
  • 4
  • 4

$(function() {

$(".test ul").find("li:gt(2)").hide();

$(".test ul").find("li:last").after("

全部>>
");

showAndHide();

});

function showAndHide() {

$(".show").click(function() {

$(this).parent().find("li:gt(2)").slideToggle();

var temp = $(this).find("a");temp.html() == "全部>>"? temp.html("收起>>") : temp.html("全部>>");

});

}

方法2:

下拉全部收起例子

.test {

padding: 10px;

color: #999999;

line-height: 150%;

padding-bottom: 15px;

border-bottom: 1px dotted #CCCCCC;

}

.active {

color: red;

}

ul {

list-style-type: none;

}

  • a
  • b
  • c
  • d
  • d
  • d
  • d
  • d
  • g
  • h
  • j
  • k
  • k
  • k
  • k
  • k
  • k
  • 1
  • 2
  • 3
  • 4
  • 4
  • 4
  • 4
  • 4
  • 4

$(function() {

$(".test ul").find("li:gt(2)").hide();

$(".test ul").find("li:last").after("

all
");

showAndHide();

});

function showAndHide() {

$(".show").click(function() {

$(this).toggleClass("active");

console.log($(this).html() == 'all');

$(this).html($(this).html() == 'all' ? 'close' : 'all');

$(this).parent().find("li").toggle();

});

}

.parent()获得当前元素上一级父元素

和.parents()获得所有的祖籍父元素

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值