我不能这个切换阅读或多或少的滑动切换工作。我非常接近,但我不确定如何显示#show-about
锚,所以它"read more"
首先显示?
$('#show-about').click(function(e){
e.preventDefault();
$('#about-hidden').slideToggle();
$(this).text( $(this).text() == 'Read More' ? "Show Less" : "Read More");
});
改变:
<a href="#" id="show-about">More...</a>
到:
<a href="#" id="show-about">Read More</a>
看来您的问题源于$(this).text() == 'Read More' ? "Show Less" : "Read More"
并且您的链接具有 text More...
。当您单击链接时,$(this).text()
equals More...
,但是您将其与 进行比较Read More
,因此更改链接以匹配该链接就可以了。
您可以使用以下方式执行此操作jQuery
:
JS
$('#show-about')
.text('Read More')
.click(function (e) {
e.preventDefault();
$('#about-hidden').slideToggle();
$(this).text($(this).text() == 'Read More' ? "Show Less" : "Read More");
});
演示:小提琴
但是,如果您可以修改 HTML 标记并完全访问它,您可以这样做:
HTML
<a href="#" id="show-about">Read More</a>
为什么你只是不写锚“阅读更多”而不是“更多......”?