3 回答
TA贡献2041条经验 获得超4个赞
首先,您必须将 html div 更改为以下几行:
<div>
<a class='more-detail' style='cursor: pointer; font-color:#0000ff;'>More...</a>
<div class='detail-section' style='display: none;'>
details details details details details details details details details details
</div>
<a class='less-detail' style='cursor: pointer; font-color:#0000ff;'>Less...</a>
</div>
然后将您的 jquery 更改为:
$(".more-detail").click(function(){
var $this = $(this);
var $detail = $this.next(".detail-section");
var $lessDetail = $detail.next(".less-detail");
$this.css("display", "none");
$detail.css("display", "block");
$lessDetail.css("display", "block");
});
$(".less-detail").click(function(){
var $this = $(this);
var $detail = $this.prev(".detail-section");
var $moreDetails = $detail.prev(".more-detail");
$detail.css("display", "none");
$moreDetails.css("display", "block");
$this.css("display", "none");
});
TA贡献1806条经验 获得超8个赞
使用this与.next()和.prev()方法:
$(".more-detail").click(function(){
$(this).next(".detail-section").css("display", "block");
$(this).next(".less-detail").css("display", "block");
$(this).css("display", "none");
});
$(".less-detail").click(function(){
$(this).prev(".detail-section").css("display", "block");
$(this).prev(".more-detail").css("display", "block");
$(this).css("display", "none");
});
- 3 回答
- 0 关注
- 151 浏览
添加回答
举报